当前位置:网站首页>GridView defines its own time for typesetting "suggestions collection"
GridView defines its own time for typesetting "suggestions collection"
2022-07-07 21:00:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack .
The company needs to do a time typesetting , Prototypes such as the following
Because of the gridView, There used to be a lot of typesetting , Most of all, I want to use one checkbox Get it done .
Later it was proved that the function could be achieved . But the layout is messy . It's better to write more honestly ( Go straight to the code )
What's wrong with bad technology? Please correct it
The first is the home page :
public class MyActivity extends Activity {
/**
* Called when the activity is first created.
*/
private HashSet<Integer> shou = new HashSet<Integer>();
private int[] Mark = {1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.button);
final WrapGridView wrapGridView = (WrapGridView) findViewById(R.id.gridview);
final DayTimeAdapter dayTimeAdapter = new DayTimeAdapter(this, Mark);
wrapGridView.setAdapter(dayTimeAdapter);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MyActivity.this, "fdsgs", Toast.LENGTH_SHORT).show();
shou = dayTimeAdapter.remark();
Iterator<Integer> iterator = shou.iterator();
while (iterator.hasNext()) {
Log.i("mark", iterator.next() + "");
}
}
});
}
}Mainly Used to pass in the representation array And accept to return the selected logo
Define your own gridView:
public class WrapGridView extends GridView{
public WrapGridView(Context context) {
super(context);
}
public WrapGridView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public WrapGridView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec=MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE>>2,MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (ev.getAction()==MotionEvent.ACTION_MOVE){
return true;// No sliding
}
return super.dispatchTouchEvent(ev);
}
}Here is Lailai no sliding It's just onMeasure Method It's just that you need to set the height and width in the code later
Finally, the adapter :
public class DayTimeAdapter extends BaseAdapter{
private ArrayList<Integer> Mark = new ArrayList<Integer>();
private String[] Time = {"8:00", "8:30", "9:00", "9:30", "10:00", "10:30", "11:00", "11:30", "12:00", "12:30", "13:00", "13:30", "14:00", "14:30",
"15:00", "15:30", "16:00", "16:30", "17:00", "17:30", "18:00", "18:30", "19:00", "19:30", "20:00"};
private LayoutInflater mInflater;
private HashSet<Integer> returnMark = new HashSet<Integer>();
public DayTimeAdapter(Context context, int[] m) {
mInflater = LayoutInflater.from(context);
for (int i = 0; i < m.length; i++) {
Mark.add(m[i]);
}
}
@Override
public int getCount() {
return Mark.size();
}
@Override
public Object getItem(int i) {
return Mark.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(final int i, View view, ViewGroup viewGroup) {
DayTimeHolder dayTimeHolder=null;
if (view == null||view.getTag()==null) {
view = mInflater.inflate(R.layout.item_time, null);
dayTimeHolder=new DayTimeHolder();
dayTimeHolder.checkBox = (CheckBox) view.findViewById(R.id.checkBox);
dayTimeHolder.timeName= (TextView) view.findViewById(R.id.textView);
view.setTag(dayTimeHolder);
}else {
dayTimeHolder = (DayTimeHolder) view.getTag();
}
dayTimeHolder.timeName.setText(Time[i]);
int a = Mark.get(i);
if (a == 0) {
view.setBackgroundColor(Color.parseColor("#04385A"));
dayTimeHolder.checkBox.setVisibility(View.INVISIBLE);
dayTimeHolder.checkBox.setClickable(false);
}
final View finalView = view;
final Handler handler = new Handler() {
public void handleMessage(Message msg) {
if (msg.what == 1) {
finalView.setBackgroundColor(Color.parseColor("#F0AB4E"));
// Log.i("mark","shoushoushou");
} else {
finalView.setBackgroundColor(Color.parseColor("#000000"));
}
}
};
dayTimeHolder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
Message msg = new Message();
if (b) {
msg.what = 1;
Log.i("mark", "111111111111");
returnMark.add(i);
} else {
msg.what = 2;
Log.i("mark", "22222222222222");
returnMark.remove(i);
}
handler.sendMessage(msg);
}
});
return view;
}
public HashSet remark() {
return returnMark;
}
}
class DayTimeHolder{
public CheckBox checkBox;// multi-select button
public TextView timeName;// Time name
}Here is the Direct initialization gridview structure .
It's used in handler and message It is necessary to dynamically update the selected status .
I haven't written this for a long time , In addition to technology, our industry has accumulated experience .
alas . The more you learn, the lazier you feel ..
.
.
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/116279.html Link to the original text :https://javaforall.cn
边栏推荐
- Measure the height of the building
- Alibaba cloud award winning experience: how to mount NAS file system through ECS
- How to meet the dual needs of security and confidentiality of medical devices?
- Data sorting in string
- Is it safe to open an account online now? I want to know where I can open an account in Nanning now?
- OneSpin 360 DV新版发布,刷新FPGA形式化验证功能体验
- [award publicity] issue 22 publicity of the award list in June 2022: Community star selection | Newcomer Award | blog synchronization | recommendation Award
- How to choose fund products? What fund is suitable to buy in July 2022?
- 单词反转实现「建议收藏」
- 最新版本的CodeSonar改进了功能安全性,支持MISRA,C ++解析和可视化
猜你喜欢

使用高斯Redis实现二级索引

最新版本的CodeSonar改进了功能安全性,支持MISRA,C ++解析和可视化

C language helps you understand pointers from multiple perspectives (1. Character pointers 2. Array pointers and pointer arrays, array parameter passing and pointer parameter passing 3. Function point
Codesonar enhances software reliability through innovative static analysis

How to meet the dual needs of security and confidentiality of medical devices?

Don't fall behind! Simple and easy-to-use low code development to quickly build an intelligent management information system

How to meet the dual needs of security and confidentiality of medical devices?
![[paper reading] maps: Multi-Agent Reinforcement Learning Based Portfolio Management System](/img/76/b725788272ba2dcdf866b28cbcc897.jpg)
[paper reading] maps: Multi-Agent Reinforcement Learning Based Portfolio Management System

【C语言】指针进阶---指针你真的学懂了吗?

CodeSonar如何帮助无人机查找软件缺陷?
随机推荐
恶魔奶爸 B1 听力最后壁垒,一鼓作气突破
凌云出海记 | 赛盒&华为云:共助跨境电商行业可持续发展
OneSpin 360 DV新版发布,刷新FPGA形式化验证功能体验
[function recursion] do you know all five classic examples of simple recursion?
Codeforces Round #296 (Div. 2) A. Playing with Paper[通俗易懂]
Is embedded system really safe? [how does onespin comprehensively solve the IC integrity problem for the development team]
如何挑选基金产品?2022年7月份适合买什么基金?
恶魔奶爸 A0 英文零基础的自我提升路
Codeforces 474 F. Ant colony
私募基金在中国合法吗?安全吗?
Cocos2d-x game archive [easy to understand]
ERROR: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
Is private equity legal in China? Is it safe?
ISO 26262 - 基于需求测试以外的考虑因素
sqlHelper的增删改查
Is it safe to open an account of BOC shares in kainiu in 2022?
Postgresql数据库character varying和character的区别说明
Introduction to referer and referer policy
Update iteration summary of target detection based on deep learning (continuous update ing)
Klocwork code static analysis tool