我寫了一個代碼來顯示圖像,在ListView中動態地按下&文本。 因此,ListView加載按鈕。我想通過單擊此按鈕來刪除ListView中的選定項目。在ListView上點擊刪除按鈕後在ListView上刪除項目
適配器類:
public class LazyAdapter extends BaseAdapter {
private Activity activity;
private String[] data;
private static LayoutInflater inflater=null;
public ImageLoaderLogoUnder imageLoader;
public LazyAdapter(Activity a, String[] d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoaderLogoUnder(activity.getApplicationContext());
}
public int getCount() {
return data.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.inflatelistview, null);
TextView text=(TextView)vi.findViewById(R.id.textView1);
ImageView image=(ImageView)vi.findViewById(R.id.imageView1);
Button btn=(Button)vi.findViewById(R.id.button1);
btn.setTag(position);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Integer index = (Integer) v.getTag();
//items.remove(index.intValue());
notifyDataSetChanged();
}
});
text.setText("item "+position);
imageLoader.DisplayImage(data[position], image);
return vi;
}
}
這是一個ListView Activity類
ShowData show = new ShowData();
String s[] = show.getData();
adapter = new LazyAdapter(this, s);
inflater = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
list = (ListView) findViewById(R.id.listView1);
list.setAdapter(adapter);
如何做到這一點?