在我的Android应用程序中,我使用分页来使用listview显示我的所有产品。在listview中有一个checkBox和一个imageview。我正在使用checkBox从listview中选择特定的图像。我从服务器获取所有图像。首先,我将所有图像放在ArryList中,然后我在android临时ArrayList中使用5个元素,并将该临时用于自定义阵列适配器并加载该5个图像。问题是当我选择一个复选框来选择特定图像并单击下一个按钮然后在新页面内我得到另一个选中的复选框。除此之外,我在每个页面中都有一个选中的按钮。如何删除?我想在Checked我点击的位置选中该复选框。我的代码如下。
private class MyCustomAdapter extends ArrayAdapter<WatchListAllEntity> {
private static final int TYPE_ITEM = 0;
private static final int TYPE_ITEM_WITH_HEADER = 1;
private ArrayList<WatchListAllEntity> mData = new ArrayList();
private LayoutInflater mInflater;
private ArrayList<WatchListAllEntity> items = new ArrayList<WatchListAllEntity>();
public MyCustomAdapter(Context context, int textViewResourceId,
ArrayList<WatchListAllEntity> items) {
super(context, textViewResourceId, items);
this.items = items;
}
public void addItem(WatchListAllEntity watchListAllEntity) {
items.add(watchListAllEntity);
}
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
final int position1 = position;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.listitempict, null);
}
watchListAllEntity = new WatchListAllEntity();
watchListAllEntity = items.get(position);
Log.i("position: iteamsLength ", position + ", " + items.size());
if (watchListAllEntity != null) {
ImageView itemImage = (ImageView) v
.findViewById(R.id.imageviewproduct);
if (watchListAllEntity.get_thumbnail_image_url1() != null) {
Drawable image = Utility.ImageOperations(watchListAllEntity.get_thumbnail_image_url1().replace(" ", "%20"),"image.jpg");
if (image != null) {
itemImage.setImageDrawable(image);
itemImage.setAdjustViewBounds(true);
} else {
itemImage.setImageResource(R.drawable.iconnamecard);
}
Log.i("status_ja , status",
watchListAllEntity.get_status_ja() + " ,"
+ watchListAllEntity.getStatus());
int NewtheStatus = Integer.parseInt(watchListAllEntity
.getStatus());
CheckBox checkBox = (CheckBox) v
.findViewById(R.id.checkboxproduct);
TextView alreadyOrderText = (TextView) v
.findViewById(R.id.alreadyordertext);
if (NewtheStatus == 1) {
alreadyOrderText.setVisibility(4);
checkBox.setVisibility(0);
} else {
checkBox.setVisibility(4);
alreadyOrderText.setVisibility(0);
}
Log.i("Loading ProccardId: ",
watchListAllEntity.get_proc_card_id() + "");
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
WatchListAllEntity watchListAllEntity2 = items
.get(position1);
Log.i("Position: ", position1 + "");
if (isChecked) {
Constants.orderList.add(watchListAllEntity2
.get_proc_card_id());
Log.i("Proc Card Id Add: ",
watchListAllEntity2.get_proc_card_id()
+ "");
} else {
Constants.orderList.remove(watchListAllEntity2
.get_proc_card_id());
Log.i("Proc Card Id Remove: ",
watchListAllEntity2.get_proc_card_id()
+ "");
}
}
});
}
}
return v;
}
答案 0 :(得分:0)
检查newpage.xml文件中的CheckBox元素是否包含android:checked =“true”语句。