當我添加項目到列表視圖,列表視圖不顯示我添加的項目。當我添加項目到適配器我想在listview中看起來...但它不起作用。我的失敗在哪裏?有關於Listview(添加/刪除/編輯)例子的例子嗎?Android ListView項目添加和刪除
適配器代碼
android.content.Context Context;
LayoutInflater inflater;
ArrayList<Item> Items=new ArrayList<>();
public MyAdapter(Context Context)
{
this.Context=Context;
}
@Override
public int getCount() {
return Items.size();
}
@Override
public Object getItem(int position) {
return Items.get(position);
}
@Override
public long getItemId(int position) {
return 0;
}
public void AddItem(Item item)
{
Items.add(item);
MyAdapter.this.notifyDataSetChanged();
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ImageButton BtnSil;
inflater=(LayoutInflater) Context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view=inflater.inflate(R.layout.fragment_lstview,parent,false);
BtnRemove=(ImageButton)view.findViewById(R.id.Remove);
BtnRemove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Urunler.remove(position);
MyAdapter.this.notifyDataSetChanged();
}
});
return view;
}
項目添加代碼
adapter.AddItem(SecilenUrun);
按照此:http://stackoverflow.com/a/22145297/1406172 –