我需要重新加載適配器,當buton被點擊。但我怎麼能執行它?我的代碼如下。如何從getView方法重新加載基本適配器
public class CustomGridAdapter extends BaseAdapter {
private Context context;
//private final String[] gridValues;
ArrayList<Bitmap> arrayList;
ImageButton i1;
//Constructor to initialize values
public CustomGridAdapter(Context context, ArrayList<Bitmap> ob) {
arrayList = ob;
this.context = context;
// this.gridValues = gridValues;
}
@Override
public int getCount() {
return arrayList.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
final int pos = position;
// LayoutInflator to call external grid_item.xml file
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View gridView;
if (convertView == null) {
gridView = new View(context);
// get layout from grid_item.xml (Defined Below)
gridView = inflater.inflate(R.layout.grid_item, null);
ImageView imageView = (ImageView) gridView
.findViewById(R.id.grid_item_image);
imageView.setImageBitmap(arrayList.get(position));
ImageButton imageButton = (ImageButton) gridView
.findViewById(R.id.imageButton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("myLogs", "Yes, onclick "+pos);
arrayList.remove(pos);
!!!THERE I NEED TO RELOAD IT
}
});
} else {
gridView = (View) convertView;
}
return gridView;
}
}
imageButton.setOnClickListener(context);這行不好 –
你是什麼意思?它不工作? – Giacomoni
是的,我不能處理按鈕onClick在另一個類 –