我已經使用Adapter類中的Adapter類的Customized Listview ROW中的兩個複選框爲此,我需要Select Only一個複選框Checkbox1行/列相同複選框2. 例如,我有一個列表視圖中的5行共10個複選框裏面的列表視圖輸出10只有一個選擇一次所有其他應該取消選擇使用Listview在同一行和列中僅選擇一個複選框/單選按鈕連同兩個複選框/單選按鈕Android
任何想法關於我試過很多但只選擇Checkbox1列 請幫忙
public class ListViewAdapter extends ArrayAdapter<Friend> {
private List<Friend> myFriends;
private Activity activity;
private int selectedPosition = -1;
String flag="";
String[]ids=new String[100];
String[]ids1=new String[100];
public ListViewAdapter(Activity context, int resource, List<Friend> objects) {
super(context, resource, objects);
this.activity = context;
this.myFriends = objects;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
// If holder not exist then locate all view from UI file.
if (convertView == null) {
// inflate UI from XML file
convertView = inflater.inflate(R.layout.item_listview, parent, false);
// get all UI view
holder = new ViewHolder(convertView);
// set tag for holder
convertView.setTag(holder);
} else {
// if holder created, get tag from view
holder = (ViewHolder) convertView.getTag();
}
holder.checkBox.setTag(position); // This line is important.
holder.checkBox1.setTag(position + 100);
holder.friendName.setText(getItem(position).getName());
holder.rdgrp.setTag(position);
ids[position]=holder.checkBox.getTag().toString();
ids1[position]=holder.rdgrp.getTag().toString();
// System.out.println("praveen"+ids[position]);
if (position == selectedPosition) {
holder.rdgrp.setActivated(true);
} else holder.rdgrp.setActivated(false);
if(holder.checkBox.getTag().equles(position)){
holder.checkBox.setOnClickListener(onStateChangedListener(holder.checkBox, position));
}else{
holder.checkBox1.setOnClickListener(onStateChangedListener(holder.checkBox1, position));
}
return convertView;
}
public View.OnClickListener onStateChangedListener(final RadioGroup gry, final int position){
return new View.OnClickListener() {
@Override
public void onClick(View v) {
if (gry.isClickable()) {
selectedPosition = position;
} else {
selectedPosition = -1;
}
notifyDataSetChanged();
}
};
}
private static class ViewHolder {
private TextView friendName;
private CheckBox checkBox,checkBox1;
public ViewHolder(View v) {
checkBox = (CheckBox) v.findViewById(R.id.check);
checkBox1 = (CheckBox) v.findViewById(R.id.check1);
friendName = (TextView) v.findViewById(R.id.name);
}
}
}
你試過了什麼? –
你可以發佈你的代碼嗎? –
是的,我發佈我的代碼在剛纔的問題 – kumar