I have an arrayadapter extending from baseadapter and using it with an arraylist for store data.I need to update individual item.So I need to give an id for each item when adding to arraylist.Then I will update it with set
method like this:
randomsList.set(position,new Random(user,1));
I mean I need a position value.Somebody said you need do implement of map
for this.But I don't know how can I do it.I need an example.
This is my class:
private static class Randoms{
private List<Random> randoms=null;
public Randoms(List<Random> randoms) {
this.randoms=randoms;
}
public Random get(int position) {
return randoms.get(position);
}
public int size() {
return randoms.size();
}
}
And this is my adapter:
private static class RandomsAdapter extends BaseAdapter{
private Randoms randoms;
private LayoutInflater inflater;
private Context context;
private RandomsAdapter(Context context,Randoms randoms) {
this.randoms=randoms;
this.inflater = LayoutInflater.from(context);
this.context=context;
}
public void updateRandoms(Randoms randoms) {
this.randoms=randoms;
notifyDataSetChanged();
}
@Override
public int getCount() {
return randoms.size();
}
@Override
public Random getItem(int position) {
return randoms.get(position);
}
@Override
public long getItemId(int position) {
return 0;
}
public View getView(int position,View convertView,ViewGroup parent) {
}
}