我有反應,我在適配器中獲取並顯示在TextView中,但問題是它在列表視圖中打印兩次項目。我檢查了答覆。它也只有一個項目。但是當我在調試模式下檢查時,循環會在適配器中打印兩次。我無法找到解決方案。例如:如果列表中有10個項目(A,B,C等),它顯示爲20個項目(A,A,B,B,C,C等),請幫助我。問題在適配器android
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;
}
}
當我檢查響應,它的顯示作爲
E/REsponse(4989): Response{"id":27136,"cast_id":3,"order":0,"credit_id":"52fe4e769251416c7515736b","profile_path":"\/rrN6d7WR.jpg","name":"Katharine Isabelle","character":"Tamara"}
2月10日至29日:01:56.934:E /最終(4989):Finaltrue (4989):響應{「id」:21320,「cast_id」:4,「order」:1,「credit_id」:「52fe4e769251416c7515736f」,「profile_path」:「/ d9YmZ.jpg」,「name」 :「丹妮爾哈里斯」,「人物」:「艾米」 } E /最終(4989):Finaltrue E /響應(4989):響應{ 「ID」:27775 「cast_id」:5, 「命令」: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)響應{「id」:61903,「cast_id」:6,「order」:3,「credit_id」:「53da2fb40e0a2652f000200d」,「profile_path」:「/ jMUbn5I63NDlqM650.jpg」,「name」:「Glenn Thomas Jacobs」字符 「:」 雅各晚安「} 2月10日至29日:01:56.937:E /決賽(4989):Finaltrue
loop?你在說什麼循環? – pskink 2014-10-28 20:23:05
當我在調試模式下檢查時,它重複該項目兩次並執行下一個項目。 @pskink你可以查看屏幕截圖 – user3557113 2014-10-28 20:29:42
get.dat()和data.get(position)在getItem()中的Log.d數據大小 – pskink 2014-10-28 20:33:45