选定的ListView项目将自动取消选中

时间:2013-08-13 20:55:59

标签: android listview

我刚创建了一个由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);
}
}

0 个答案:

没有答案