I have an adapter and I want to add data to adapter.This is my source code:
private static class Random{
public JsonObject randomData=null;
public Integer badgeNumber=null;
private Random(JsonObject randomData,Integer badgeNumber) {
this.randomData=randomData;
this.badgeNumber=badgeNumber;
}
}
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();
}
}
private static class RandomsAdapter extends BaseAdapter{
private Randoms randoms;
private LayoutInflater inflater;
private RandomsAdapter(Context context,Randoms randoms) {
this.randoms=randoms;
this.inflater = LayoutInflater.from(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) {
View view=convertView;
if (convertView == null) {
convertView=inflater.inflate(R.layout.random_bars,parent,false);
}
Random item=getItem(position);
Log.w("testt",""+item);
return convertView;
}
}
And I am defining the adapter with this code:
Randoms randoms=new Randoms(randomsList);
randomsAdapter=new RandomsAdapter(this,randoms);
listView = (ListView)findViewById(R.id.list);
listView.setAdapter(randomsAdapter);
When I try to add a data I am using this line
randomsList.add(new Random(result.get(i).getAsJsonObject(),1));
But this not working,I can't see any log with "testt" tag.How can I resolve this ?
I mean getView
method is not working.