私のAndroidアプリケーションでは、リストビューを使用してすべての製品を表示するためにページネーションを使用しました。listview 内には、1 つの checkBox と 1 つの imageview があります。リストビューから特定の画像を選択するためにcheckBoxを使用しています。サーバーからすべての画像を取得しています。まず、ArryList 内のすべての画像を取得してから、Android の一時的な ArrayList 内の 5 つの要素を取得し、その一時的な要素をカスタム配列アダプターに使用して、その 5 つの画像を読み込みます。問題は、1 つのチェックボックスを選択して特定の画像を選択し、次のボタンをクリックすると、新しいページ内で別のチェックボックスが選択されることです。これに加えて、すべてのページ内に 1 つの選択されたボタンを取得しています。これを削除するには?クリックした場所でチェックボックスをオンにしたい。私のコードを以下に示します。
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;
}