我刚刚创建了一个由 CursorLoader 支持的 ListView,当单击 ListView 中的项目时,它们仍然突出显示。
这是xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@android:id/list"
android:choiceMode="singleChoice"
android:listSelector="@android:color/darker_gray"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
我的问题是,在另一个片段中,我编辑了一些对内部数据库进行更改的数据,似乎一旦我的 SyncAdapter 运行,所选项目就会自动取消选择。有没有人遇到过此类问题?
编辑:
这是片段的代码:
public class BidItemsFragment extends ListFragment implements
LoaderManager.LoaderCallbacks<Cursor> {
public static final String ITEM_TYPE_BIDITEM= "B";
private SimpleCursorAdapter mAdapter;
private ListView mList;
private Context mContext;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mContext = getActivity();
fillData();
View v = inflater.inflate(R.layout.biditems_list, container, false);
mList = (ListView) v.findViewById(android.R.id.list);
return v;
}
private void fillData() {
String[] from = new String[] { Columns.COLUMN_ITEMNUMBER };
int[] to = new int[] { R.id.biditem_num };
getLoaderManager().initLoader(0, null, this);
mAdapter = new SimpleCursorAdapter(mContext, R.layout.biditems_row, null, from, to, 0);
setListAdapter(mAdapter);
}
@Override
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
String[] projection = Columns.getColumns(RawContract.PARAM_SEBIDITEM);
String selection = Columns.COLUMN_SYSID + "=?";
String selectionArgs[] = { "1" };
CursorLoader cursorLoader = new CursorLoader(mContext,
BidProvider.CONTENT_URI_SEBIDITEM, projection, selection, selectionArgs, null);
return cursorLoader;
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
mAdapter.swapCursor(data);
}
@Override
public void onLoaderReset(Loader<Cursor> loader) {
mAdapter.swapCursor(null);
}
}