我想通過意向幫助將列表視圖中存在的複選框的位置傳遞給其他活動。但它在另一項活動中顯示我爲空。或者有人可以告訴我如何使用下面的代碼將選中的複選框數據傳遞給另一個活動?未通過其他活動的複選框數據
我想從各個複選框的列表視圖中將值存儲在數組中。然後轉移到另一個活動
public class MyAdapter extends ArrayAdapter<Model> {
int getPosition;
Intent in;
private final List<Model> list;
public final Activity context;
boolean checkAll_flag = false;
boolean checkItem_flag = false;
public MyAdapter(Activity context, List<Model> list) {
super(context, R.layout.row, list);
this.context = context;
this.list = list;
}
static class ViewHolder {
protected TextView text;
protected CheckBox checkbox;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder = null;
if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
convertView = inflator.inflate(R.layout.row, null);
viewHolder = new ViewHolder();
viewHolder.text = (TextView) convertView.findViewById(R.id.label);
viewHolder.checkbox = (CheckBox) convertView
.findViewById(R.id.check);
viewHolder.checkbox
.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
getPosition = (Integer) buttonView.getTag(); // setTag.
}
});
convertView.setTag(viewHolder);
convertView.setOnClickListener(new MyCustomItemClickListener(getPosition));
convertView.setTag(R.id.label, viewHolder.text);
convertView.setTag(R.id.check, viewHolder.checkbox);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.checkbox.setTag(position); // This line is important.
viewHolder.text.setText(list.get(position).getName());
viewHolder.checkbox.setChecked(list.get(position).isSelected());
return convertView;
}
class MyCustomItemClickListener implements OnClickListener {
MyCustomItemClickListener(int getPositionx) {
/*
* Whatever initialization you need can be done here. You can pass
* values in constructor when calling it from getview and use with
* intent extras
*/
in = new Intent(context, YourActivity.class);
in.putExtra("aa", getPositionx);
}
@Override
public void onClick(View arg0) {
// Launch Activity
context.startActivity(in);
}
}
}
您需要將複選框文本傳遞給其他活動或複選框位置? – 2013-02-23 06:28:08
你是如何從意圖中提取價值的?你可以顯示代碼,因爲你實際上在代碼中是空的,不是嗎? – 2013-02-23 06:33:38
我想從各個複選框的列表視圖中將值存儲在數組中。然後轉移到另一個活動 – 2013-02-23 13:21:01