【发布时间】:2018-01-25 19:53:17
【问题描述】:
我有带有复选框和文本视图的列表视图。当我选中复选框时,更改同一行中的文本。这样我将检查列表视图中的所有复选框并更改每一行中的文本。谁能用示例代码解释一下?
public class DialogAdapter extends BaseAdapter{
//private LayoutInflater inflater = null;
ArrayList<String> timeList = new ArrayList<String>();
Context context;
public DialogAdapter(Context context, ArrayList<String> timeList) {
// TODO Auto-generated constructor stub
this.context = context;
this.timeList = timeList;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
//return timings.size();
return timeList.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return timeList.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@SuppressLint("ViewHolder")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
//String timing = "10-30,14-08,16-30,19-00";
LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.dialog_row_list,null);
//timeListView.setVisibility(convertView.VISIBLE);
TextView txt_time=(TextView) convertView.findViewById(R.id.text_times);
txt_time.setText(timeList.get(position).toString());
EditText comments=(EditText)convertView.findViewById(R.id.editText_comment);
final TextView txt_Action=(TextView) convertView.findViewById(R.id.textView_act);
CheckBox cBox= (CheckBox) convertView.findViewById(R.id.checkBox_action);
cBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@SuppressLint("ResourceAsColor")
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
int getPosition = (Integer) buttonView.getTag();
timeList.get(getPosition).setSelected(buttonView.isChecked());
Toast.makeText(context, "position"+getPosition, 0).show();
if(isChecked){
txt_Action.setText("finished");
txt_Action.setTextColor(R.color.Green);
}
else{
txt_Action.setText("UnChecked");
txt_Action.setTextColor(R.color.Red);
}
}
});
return convertView;
}
}
这是我的代码,请检查n给出解决方案如何在检查列表视图中的复选框时更改列表视图文本???
【问题讨论】:
标签: android listview checkbox textview