0

I have an app utilizing Action Bar with Tab navigation which displays a listview via custom cursor adapter and then displays detail data when a listview item is clicked. It all works well when my device is in portrait orientation.

My problem arises when my device is in landscape orientation. When I click on an item, the detail view displays the item at the top of the visible list. ie: items Accolate - Actonel are visible in the list. No matter which item I click on, Accolate is displayed.

Screenshot:

landscape screenshot

Here is my onListItemClick method:

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

I'm using fragments for my listview and detailview. The only difference from portrait to landscape is I'm connecting to a frame in landscape mode. Here is my adapter code:

    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));

    }
}       

I have logged the position during the click and it matches the correct record in my cursor, yet the adapter is displaying the wrong data.

Any thoughts or suggestions would be appreciated. thanks in advanced.

4

1 回答 1

0

我发现是什么导致了我的问题。我的 ListFragment 中有以下命令:

 getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);

我认为这与列表视图中的标记行有关

于 2013-09-15T18:17:11.103 回答