私も同様の問題を抱えていましたが、カスタム リストの項目をクリックすると、画面上の項目が順番に逆になってしまいました。もう一度クリックすると、元の位置に戻ります。
これを読んだ後、 getView メソッドをオーバーロードしているコードをチェックしました。私はconvertedViewからビューを取得していましたが、それがnullの場合は、それが自分のものを構築するときです。ただし、ブレークポイントを配置した後、すべてのクリックでこのメソッドが呼び出され、その後のクリックでは、convertedView が null ではないため、項目が設定されていないことがわかりました。
それが何であったかの例を次に示します。
public View getView(int position, View convertView, ViewGroup parent)
{
View view = convertView;
if (view == null)
{
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.listitemrow, null);
RssItem rssItem = (RssItem) super.getItem(position);
if (rssItem != null)
{
TextView title = (TextView) view.findViewById(R.id.rowtitle);
if (title != null)
{
title.setText(rssItem.getTitle());
}
}
}
return view;
}
微妙な変更は、ビューの null チェックの右中かっこをインフレートの直後に移動することです。
public View getView(int position, View convertView, ViewGroup parent)
{
View view = convertView;
if (view == null)
{
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.listitemrow, null);
}
RssItem rssItem = (RssItem) super.getItem(position);
if (rssItem != null)
{
TextView title = (TextView) view.findViewById(R.id.rowtitle);
if (title != null)
{
title.setText(rssItem.getTitle());
}
}
return view;
}
これが、同じ問題を経験している他の人に役立つことを願っています。