いくつかの製品を表示する ListView があります。BaseAdapter クラスを拡張するオブジェクトを使用して ListView にデータを入力します。より正確には getView(..) メソッドを使用します。ユーザーがタップするとWebページに移動するすべてのitemViewにTextViewの「リンク」があります。私の基本アダプターでは、製品にリンクが含まれている場合にのみ、TextView にリスナーを設定します。getView(..) メソッドでデバッグを行いましたが、すべて正常に動作しますが、getView メソッドを終了した後、リンクを持たないアイテムがある場合、別のアイテムからリンク/リスナーを取得しますリストビュー。
アダプタ クラス:
public class MatchListBaseAdapter extends BaseAdapter {
private static ArrayList<Match> matchesArrayList;
private LayoutInflater l_Inflater;
private OnClickListener onClickListener;
public MatchListBaseAdapter(Context context, View.OnClickListener listener, ArrayList<Match> results,Activity a) {
matchesArrayList = results;
onClickListener = listener;
l_Inflater = LayoutInflater.from(context);
}
public int getCount() {
return matchesArrayList.size();
}
public Object getItem(int position) {
return matchesArrayList.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = l_Inflater.inflate(R.layout.itemlist_match, null);
holder = new ViewHolder();
holder.name = (TextView) convertView.findViewById(R.id.oferNameMLI2);
holder.expireDate = (TextView) convertView.findViewById(R.id.expireDateMLI);
holder.price = (TextView) convertView.findViewById(R.id.priceMLI);
holder.companyName = (TextView) convertView.findViewById(R.id.compNameMLI);
holder.productImage = (ImageView) convertView.findViewById(R.id.productImageMLI);
holder.companyImage = (ImageView) convertView.findViewById(R.id.companyImageMLI);
holder.description = (TextView) convertView.findViewById(R.id.moreDetailsMLI);
holder.digitalySigned = (ImageView) convertView.findViewById(R.id.digitalSignatureImageView);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
//populating the holder.. doesn`t have any relevance..
if(matchesArrayList.get(position).getCompanyLink() != null){
holder.companyImage.setOnClickListener(onClickListener);
holder.companyImage.setTag(position);
}
return convertView;
}
static class ViewHolder {
TextView name;
TextView expireDate;
TextView price;
TextView companyName;
TextView description;
ImageView productImage;
ImageView companyImage;
ImageView digitalySigned;
}
}
作成時のアクティビティ:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listview_layout);
matches = DataManager.getInstance().getListSubscription().get(DataManager.getInstance().getSubscriptionPosition()).getMatchesList();
ListView lv1 = (ListView) findViewById(R.id.listView_layout);
DataManager.getInstance().setAdapterMatch(new MatchListBaseAdapter(this, this, matches,this));
lv1.setAdapter(DataManager.getInstance().getAdapterMatch());
}
getView(..) メソッドでデバッグを行ったことをもう一度言いたいのですが、問題はありませんでした。フローは正しいものでしたが、その後the items in the listView that doesn't supposed to have a listener on the TextView it had from the other items.
Also this happens always for the first item in the listView .. and it is populated with the link from the last item in the listView that contains a link.
この問題をよく検索しましたが、関連するものは何も見つかりませんでしたが、convertView に問題があると思いますが、わかりません..
ありがとう