android游标适配器在横向模式下显示错误数据(android cursor adapter display wrong data in landscape mode)

编程入门 行业动态 更新时间:2024-10-28 02:35:23
android游标适配器在横向模式下显示错误数据(android cursor adapter display wrong data in landscape mode)

我有一个应用程序,利用带有标签导航的操作栏,通过自定义光标适配器显示列表视图,然后在单击列表视图项目时显示详细数据。 当我的设备处于纵向时,一切正常。

当我的设备处于横向时,我的问题就出现了。 单击某个项目时,详细视图将显示可见列表顶部的项目。 即:项目Accolate - Actonel在列表中可见。 无论我点击哪个项目,都会显示Accolate。

截图:

这是我的onListItemClick方法:

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

我正在使用片段查看我的listview和detailview。 从肖像到风景的唯一区别是我在横向模式下连接到一个框架。 这是我的适配器代码:

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 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:

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.

最满意答案

我发现了导致我问题的原因。 我的ListFragment中有以下命令:

getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);

我认为这与在listview中标记行有关

I discovered what was causing my problem. I had the following command in my ListFragment:

getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);

I thought it had to do with tagging lines in a listview

更多推荐

本文发布于:2023-08-08 00:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466786.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:游标   适配器   横向   错误   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!