I have response where i am getting in adapters and displaying in textview but problem is it prints the item two times in listview. I checked the response. It also have only one item. But when I checked in debug mode, the loop prints in adapter two times. I couldn't find solution for this. For eg: in a list if it has 10 items.(A,B,C etc.,) it displays as 20 items (A,A,B,B,C,C etc.,)Please help me.
public class ListAdaptersTest extends BaseAdapter {
ArrayList<Persons> actorList;
LayoutInflater vi;
int Resource;
ViewHolder holder;
ImageLoader loader;
Persons movie;
Activity activity;
public static final String NAME="name";
public static final String image="image";
ArrayList<Persons> data=new ArrayList<Persons>();
public ListAdaptersTest(Activity context, int resource, ArrayList<Persons> movies) {
vi = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Resource = resource;
data=movies;
activity=context;
loader=new ImageLoader(context.getApplicationContext());
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// convert view = design
View v = convertView;
try{
if (v == null) {
holder = new ViewHolder();
v = vi.inflate(Resource, null);
holder.tvName = (TextView) v.findViewById(R.id.tvname);
v.setTag(holder);
} else {
holder = (ViewHolder) v.getTag();
}
movie = null;
movie = data.get(position);
final String name=movie.getName();
holder.tvName.setText(name);
}
catch (Exception ex) {
ex.printStackTrace();
}
return v;
}
static class ViewHolder {
public TextView tvName;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return data.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return data.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
}
When I check the response, it's displaying as
E/REsponse(4989): Response{"id":27136,"cast_id":3,"order":0,"credit_id":"52fe4e769251416c7515736b","profile_path":"\/rrN6d7WR.jpg","name":"Katharine Isabelle","character":"Tamara"}
10-29 02:01:56.934: E/Final(4989): Finaltrue E/REsponse(4989): Response{"id":21320,"cast_id":4,"order":1,"credit_id":"52fe4e769251416c7515736f","profile_path":"/d9YmZ.jpg","name":"Danielle Harris","character":"Amy"} E/Final(4989): Finaltrue E/REsponse(4989): Response{"id":27775,"cast_id":5,"order":2,"credit_id":"52fe4e769251416c75157373","profile_path":"/gNeWQz9oqF.jpg","name":"Chelan Simmons","character":"Kayla"} E/Final(4989): Finaltrue 10-29 02:01:56.937: E/REsponse(4989): Response{"id":61903,"cast_id":6,"order":3,"credit_id":"53da2fb40e0a2652f000200d","profile_path":"/jMUbn5I63NDlqM650.jpg","name":"Glenn Thomas Jacobs","character":"Jacob Goodnight"} 10-29 02:01:56.937: E/Final(4989): Finaltrue