0

カスタムカーソルアダプターを介してリストビューを表示し、リストビューアイテムをクリックすると詳細データを表示するタブナビゲーション付きのアクションバーを利用するアプリがあります。デバイスが縦向きの場合、すべてうまく機能します。

デバイスが横向きの場合に問題が発生します。アイテムをクリックすると、詳細ビ​​ューの表示リストの一番上にアイテムが表示されます。つまり、項目 Accolate - Actonel がリストに表示されます。どの項目をクリックしてもAccolateが表示されます。

スクリーンショット:

横向きのスクリーンショット

これが私の onListItemClick メソッドです:

public void onListItemClick(ListView parent, View v, int position, long id) { 
mCurCheckPosition = position;
items.setSelectedPosition(position, cursor);
}

リストビューと詳細ビューにフラグメントを使用しています。縦向きと横向きの唯一の違いは、横向きモードでフレームに接続していることです。これが私のアダプターコードです:

    public class MyListAdapter extends SimpleCursorAdapter {

    @SuppressWarnings("deprecation")
    public MyListAdapter(Context context, int layout, Cursor cursor, String[] from, int[] to) {
        super(context, layout , cursor, from, to);
    }

    public void setSelectedPosition(int position, Cursor cursor) {

        // create data array
        String [] data = new String[] { 
                cursor.getString(5),
                cursor.getString(6), 
                cursor.getString(7),
                cursor.getString(8), 
                cursor.getString(9), 
                cursor.getString(10),
                cursor.getString(4)
        };

        // create the detail fragment
        Bundle bundle = new Bundle();
        FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();

        if (mDualPane == false) {
            DetailFragment detailFragment = new DetailFragment();
            bundle.putStringArray("Data", data);
            detailFragment.setArguments(bundle);
            ft.replace(android.R.id.content, detailFragment);   
            ft.addToBackStack(null);           
            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); 
            ft.commit();
        } else {
            DetailFragment detailFragment = new DetailFragment();
            bundle.putStringArray("Data", data);
            detailFragment.setArguments(bundle);
            ft.replace(R.id.details, detailFragment);           
            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); 
            ft.commit();
        }
    }


    @Override
    public void bindView(View view, Context context, Cursor cursor) {

        // create the title textview
        TextView title = (TextView) view.findViewById(R.id.item_title);
        title.setText(cursor.getString(4));

    }
}       

クリック中に位置をログに記録しましたが、カーソル内の正しいレコードと一致していますが、アダプターは間違ったデータを表示しています。

ご意見やご提案をいただければ幸いです。ありがとうございます。

4

1 に答える 1

0

問題の原因を発見しました。ListFragment に次のコマンドがありました。

 getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);

リストビューの行にタグを付けることに関係していると思いました

于 2013-09-15T18:17:11.103 に答える