public class ImageAdapter extends BaseAdapter
{
private LayoutInflater mInflater;
private Context mContext;
public ImageAdapter(Context context)
{
mContext = context;
}
public int getCount()
{
return count;
}
public Object getItem(int position)
{
return position;
}
public long getItemId(int position)
{
return position;
}
public View getView(final int position, View convertView, ViewGroup parent)
{
ViewHolder holder;
if (convertView == null)
{
holder = new ViewHolder();
convertView = LayoutInflater.from(mContext).inflate(R.layout.state_info, null);
holder.textview = (TextView) convertView.findViewById(R.id.thumbImage);
holder.checkbox = (CheckBox) convertView.findViewById(R.id.itemCheckBox);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
holder.checkbox.setId(position);
holder.textview.setId(position);
holder.checkbox.setOnClickListener(new OnClickListener() {
public void onClick(View v)
{
// String h="hello";
CheckBox cb = (CheckBox) v;
int id = cb.getId();
if(cb.isChecked())
{
cb.setChecked(false);
}
Toast.makeText(Four.this, "Selected CheckBox ID" + v.getId(), Toast.LENGTH_SHORT).show();
}
});
holder.textview.setText(items.get(position).getName());
holder.checkbox.setChecked(thumbnailsselection[position]);
holder.id = position;
return convertView;
}
public void clear()
{
CheckBox cb=(CheckBox)findViewById(R.id.itemCheckBox);
// int id=cb.getId();
for(int j=0;j<count;j++)
{
cb.setChecked(false);
}
}
}
class ViewHolder
{
TextView textview , textIndexId;
CheckBox checkbox;
int id;
}
0
A
回答
0
公共類ImageAdapter延伸BaseAdapter { 私人LayoutInflater mInflater; private Context mContext; public ImageAdapter(Context context) mContext = context; } public int getCount() { return count; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(final int position,View convertView,ViewGroup parent) ViewHolder holder; if(convertView == null) {
convertView = LayoutInflater.from(mContext).inflate(R.layout.state_info,null);
holder = new ViewHolder();
holder.textview = (TextView) convertView.findViewById(R.id.thumbImage);
holder.checkbox = (CheckBox) convertView.findViewById(R.id.itemCheckBox);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
convertView.setTag(holder);
//holder.checkbox.setId(position);
holder.textview.setId(position);
holder.checkbox.setId(position);
holder.checkbox.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
for (int i = 0; i < count; i++)
{
if (v.getId() == i)
{
thumbnailsselection[i] = true;
Log.v("check", ""+position);
}
else
{
thumbnailsselection[i] = false;
}
}
notifyDataSetChanged();
}
});
if (thumbnailsselection[position])
{
holder.checkbox.setChecked(true);
}
else
{
holder.checkbox.setChecked(false);
}
holder.textview.setText(items.get(position).getName());
holder.checkbox.setChecked(thumbnailsselection[position]);
holder.id = position;
return convertView;
}
}
+0
其作品可以直接修改代碼 – user2294439
0
你可以做一兩件事,而使用複選框可以使用氡按鈕,但只是改變了風格複選框
相關問題
- 1. 如何在AlertDialog中選擇單選項複選框android?
- 2. 如何使用Android複選框,單選按鈕OnsenUI ios7主題
- 3. 如何使用單選按鈕選項中的複選框?
- 4. 如何在android中創建單選的AlertDialog複選框?
- 5. 如何在選中多個複選框後禁用複選框?
- 6. 如何在選擇單個複選框時選中所有複選框
- 7. 如何在Android對話框中選中複選框?
- 8. 如何在Android應用中默認選中「App Hide」複選框?
- 9. 如何在stimulsoft中使用複選框
- 10. 如何在Python中使用複選框
- 11. 如何在PHP中使用複選框?
- 12. 如何爲android中的所有複選框創建單個複選框事件?
- 13. 如何使用複選框
- 14. 如何使用複選框
- 15. 如何使用struts2在選擇框中添加複選框
- 16. 如何選中複選框?
- 17. 如何在java中使用selenium webdriver選擇單選按鈕和複選框?
- 18. 如何使用單選按鈕啓用/禁用複選框?
- 19. 如何使複選框被選中?
- 20. 使用JSF的單選複選框
- 21. 如何在選擇複選框時使用javascript選擇一排單選按鈕
- 22. 如何在YII中動態禁用複選框的單個複選框
- 23. 如何在OnItemClickListener()中選中複選框?
- 24. 如何在取消選中複選框時選中選中單選按鈕
- 25. AlertDialog複選框在Android中
- 26. jQgrid:禁用複選框單擊並僅在複選框被單擊時選中複選框
- 27. 如何設置複選框或單選
- 28. 如何使用單個複選框使用vb.net檢查/取消選中所有複選框?
- 29. 在listivew中的Android複選框選擇
- 30. 如何使用開關在jQuery中選中複選框?
什麼是你的問題 –
看來,他是填充自定義佈局項目一個ListView(因此ViewHolderPattern),每個都包含一些文本和一個複選框。現在,這些視圖中只有一個應該可以一次檢查。 –