-2

アダプターを取得してテキストビューに表示するという応答がありますが、問題はリストビューでアイテムを2回印刷することです。レスポンスを確認しました。また、アイテムは1つだけです。しかし、デバッグ モードでチェックすると、ループがアダプタに 2 回出力されます。これに対する解決策が見つかりませんでした。例:リストに10個のアイテム(A、B、Cなど)がある場合、20個のアイテム(A、A、B、B、C、Cなど)として表示されます。助けてください。

 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"}

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","プロファイルパス":"/jMUbn5I63NDlqM650.jpg","name":"Glenn Thomas Jacobs","character":"Jacob Goodnight"} 10-29 02:01:56.937: E/Final(4989): Finaltrue

4

2 に答える 2

0

public View getView メソッドで、このコード行をコメントアウトしてみてください

if (v == null) {

これは、リサイクルの問題による問題の原因となる可能性があります。

于 2014-10-28T20:39:19.067 に答える