标签: simplecursoradapter

为什么cursorLoader没有通知源数据的变化?

我有一个简单的contentProvider,一个带有ListView的布局和一个用于在内容Provider和CursorLoader中添加Items的按钮.的http://developer.android.com/reference/android/app/LoaderManager.LoaderCallbacks.html#onLoadFinished(android.content.Loader,d)参考指出

Loader将监控数据的变化,并通过此处的新呼叫向您报告.您不应该自己监控数据.例如,如果数据是Cursor并将其放在CursorAdapter中,请使用CursorAdapter(android.content.Context,android.database.Cursor,int)构造函数,而不传入FLAG_AUTO_REQUERY或FLAG_REGISTER_CONTENT_OBSERVER(即使用0表示flags参数).这可以防止CursorAdapter自己观察Cursor,这是不需要的,因为当发生更改时,你会得到一个新的Cursor,在这里抛出另一个调用.

但是onLoadFinished方法中的Log.info行没有执行,listView没有刷新.这是我的(简单)代码:

public class HomeActivity extends FragmentActivity implements LoaderManager.LoaderCallbacks<Cursor>{
static final String TAG = "HomeActivity";
SimpleCursorAdapter adapter;
ListView listAnnunciVicini;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home);

    listAnnunciVicini = (ListView) findViewById(R.id.lista_annunci_vicini);

    adapter = new SimpleCursorAdapter(this, R.layout.list_item, null, 
            new String[] {
                    ContentDescriptor.Annunci.Cols.ID, 
                    ContentDescriptor.Annunci.Cols.TITOLO, 
                    ContentDescriptor.Annunci.Cols.DESCRIZIONE 
            }, new int[] { 
                    R.id.list_annunci_item_id_annuncio, 
                    R.id.list_annunci_item_titolo_annuncio,
                    R.id.list_annunci_item_descrizione_annuncio
            }, 0);
    listAnnunciVicini.setAdapter(adapter);

    // Prepare the loader. Either re-connect with an existing one,
    // or start a new one.
    getSupportLoaderManager().initLoader(0, null, this).forceLoad();
}

public void addRandomItem(View sender) { …
Run Code Online (Sandbox Code Playgroud)

android cursor simplecursoradapter

7
推荐指数
1
解决办法
8063
查看次数

Android ListView刷新

我有一个Listview从sqlite数据库拉取并显示数据.数据库第一列中的数据显示在ListView单击中,单击时,Activity开始显示与第一列关联的列的其余部分.编辑数据时ListView需要更新以反映这一点,但除非重新启动应用程序,否则它不会显示更新.

我已经打过电话,notifyDataSetChanged()startActivityForResult()在我的onResume()方法,但没有奏效.我应该使用什么方法来完成ListView当前代码的更新?

我理解SimpleCursorAdapter可以使用,我试图实现该代码没有成功.我是一个新手,需要实际的代码才能理解需要做什么.

public class LoginList extends Activity implements OnClickListener, OnItemClickListener {
    private ListView loginList;
    private Button webLogin;

    private ListAdapter loginListAdapter;

    private ArrayList<LoginDetails> loginArrayList;

    @Override 
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.login_listview);
        loginList = (ListView)
        findViewById(R.id.loginlist);
        loginList.setOnItemClickListener(this);

        webLogin = (Button)
        findViewById(R.id.button3);
        webLogin.setOnClickListener(this);

        loginArrayList = new ArrayList<LoginDetails>();
        loginListAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, populateList());
        loginList.setAdapter(loginListAdapter);
    }

    @Override
    public void onClick (View v) {
        Intent …
Run Code Online (Sandbox Code Playgroud)

android onresume android-listview simplecursoradapter notifydatasetchanged

7
推荐指数
3
解决办法
7717
查看次数

swapCursor未定义错误

我在创建CursorLoader时收到"swapCursor(Cursor)未定义"错误.我导入了android.support.v4(app.LoaderManager,app.LoaderManager.Loader,Content.CursorLoader,content.Loader).不知道我能做些什么来纠正这个问题.请指教.

装载机:

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.app.ListFragment;
import android.support.v4.widget.CursorAdapter;



public class LoginList extends FragmentActivity implements OnClickListener, 
AdapterView.OnItemClickListener, LoaderManager.LoaderCallbacks<Cursor> {

    private ListView loginList;
    private Button webLogin;
    private SimpleCursorAdapter adapter;


    @Override 
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login_listview);

        loginList = (ListView)findViewById(R.id.loginlist);
        loginList.setOnItemClickListener(this);

        webLogin = (Button)findViewById(R.id.button3);
        webLogin.setOnClickListener(this);



        //Specify fileds to display in the list
        String[] from = new String[] { ListProvider.COLUMN_NAME_SITE };

        //Bind fields to listview
        int[] to = new int[] {R.id.loginlist};

        // Create CursorAdapter and …
Run Code Online (Sandbox Code Playgroud)

android listview cursor android-arrayadapter simplecursoradapter

7
推荐指数
1
解决办法
1467
查看次数

如何使用Cursor Adapter刷新listView

我创建了一个ListView使用CursorAdapter.现在我正在尝试更新ListView和刷新ListView的值.

但我无法弄明白.如何使用LoaderchangeCursor()刷新我的ListView

以下是我的设置代码CursorAdapter:

// SucessFully在这里完成

SQLDataSore datastore = new SQLDataSore(PrintContent.this);

Cursor cursor                 = datastore.getJSONData();

final CursorDemo cursorDemo = new CursorDemo(PrintContent.this, cursor);

list_View.setAdapter(cursorDemo);
Run Code Online (Sandbox Code Playgroud)

Button onClick正在将值更新到数据库// SucessFully完成

btn_check.setOnClickListener( new OnClickListener() {

            @Override
            public void onClick(View view ) {

                String editTextValue = edit_check.getText().toString();

                if (editTextValue!=null) {


                    SQLDataSore sqlDataSore = new SQLDataSore(PrintContent.this);

                    Cursor cursor_update = sqlDataSore.updateData(editTextValue);

//Here How Should I update my ListView ...?
                }

            }
Run Code Online (Sandbox Code Playgroud)

我的UpdateData方法:

public Cursor …
Run Code Online (Sandbox Code Playgroud)

android listview android-listview simplecursoradapter android-cursoradapter

7
推荐指数
1
解决办法
2万
查看次数

如何对CursorLoader结果进行排序?

我使用CursorLoader查询结果,这不是我想在ListFramgenet中显示的顺序.怎么排序呢?

我用它来设置适配器:

    mAdapter = new SimpleCursorAdapter(getActivity(),
            android.R.layout.simple_list_item_2, null,
            new String[] { "name", "distance"},
            new int[] { android.R.id.text1, android.R.id.text2 }, 0);
    setListAdapter(mAdapter);

    // Start out with a progress indicator.
    setListShown(false);

    // Prepare the loader.  Either re-connect with an existing one,
    // or start a new one.
    getLoaderManager().initLoader(0, null,  this);
Run Code Online (Sandbox Code Playgroud)

创建加载器:

public Loader<Cursor> onCreateLoader(int id, Bundle args) {

    return new CursorLoader(getActivity(), 
            Uri.withAppendedPath(TraceTable.CONTENT_URI, "latest"),
            MEMBERS_PROJECTION,
            null,
            null,
            null);        

}


public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    mAdapter.changeCursor(data);

    // The list should now be …
Run Code Online (Sandbox Code Playgroud)

android simplecursoradapter android-cursorloader

7
推荐指数
1
解决办法
1万
查看次数

Android - 获取具有街道地址的联系人列表,但没有像Skype这样的低价值地址,其中地址只是一个城市和州

我有一个光标检索应用程序上有街道地址的所有联系人.然后将此光标传递到适配器.到现在为止还挺好.除了我还得到一堆只有州/国家信息的低价值联系人(主要来自Skype).是否有一种简单的方法来修改URI以跳过这些?

public Cursor getDirectoryList (CharSequence constraint)  {

        String[] selectionArguments = { "%"+constraint.toString()+"%" };
        String selection = ContactsContract.CommonDataKinds.StructuredPostal.DISPLAY_NAME + " like ?";

        Uri uri = ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_URI;
        String sortOrder = ContactsContract.CommonDataKinds.StructuredPostal.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
        Cursor cr = getContentResolver().query(uri, null, selection, selectionArguments, sortOrder);

        return cr;
    }
Run Code Online (Sandbox Code Playgroud)

android android-contentresolver street-address simplecursoradapter

7
推荐指数
1
解决办法
169
查看次数

从Android中的SQL查询中的CursorAdapter支持的Spinner获取String值

我的代码在这里是非常错误的,我不确定你会如何正确地做到这一点.我有一个Spinner,它通过CursorAdapter从SQLite数据库查询填充.我需要获取当前所选项目的文本(值).我试过这个垃圾:

((Cursor)prdSpn.getItemAtPosition(prdSpn.getSelectedItemPosition())).getString(prdSpn.getSelectedItemPosition())
Run Code Online (Sandbox Code Playgroud)

获取文本,但每次都崩溃.这样做的正确方法是什么?这里有一些可能相关的附加代码:

/// qc defined above as a SimpleCursorAdapter
/////////setup product selection spinner from db
prdSpn = (Spinner)findViewById(R.id.prd_spn);
Cursor prdCur = null;
try {
    prdCur = mDb.query(smsDbSchema.ProductSchema.TABLE_NAME, null, null, null, null, null, null);
} catch(Exception e) {
    Log.e("smsdb", e.toString());
}
prdCur.moveToFirst();
startManagingCursor(prdCur);
qc = new SimpleCursorAdapter(
    this,
    android.R.layout.simple_spinner_item,
    prdCur,
    new String[] {smsDbSchema.ProductSchema.COLUMN_NAME},
    new int[] {android.R.id.text1}
);
qc.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
prdSpn.setAdapter(qc);
Run Code Online (Sandbox Code Playgroud)

java android spinner simplecursoradapter

6
推荐指数
1
解决办法
3168
查看次数

如何设置视图或活动来处理先前的列表活动?例如“查看完整的详细信息页面”

这是我的ListActivity ,单击列表后,它将启动一个新列表activity,其中显示每个景点的完整详细信息。我不知道如何实现完整的详细信息页面。你们能给我展示一些从以前的数据中检索数据的完整详细活动的代码吗list

公共类 AttractionsListActivity 扩展 ListActivity {



    私有静态MyDB mDbHelper;
    String[] from = new String[] { Constants.TITLE_NAME , Constants.ADDRESS_NAME };
    int[] to = new int[] {R.id.place_title, R.id.place_address};
    私有游标c;


    @覆盖
    公共无效onCreate(捆绑保存实例状态){
        super.onCreate(savedInstanceState);


        mDbHelper = new MyDB(this);
        mDbHelper.open();
        c = mDbHelper.getplaces();
setListAdapter(新的SimpleCursorAdapter(这个,
                  R.layout.list_place,c,
                  从到));

        最终ListView lv = getListView();

lv.setOnItemClickListener(new OnItemClickListener() {
            公共无效onItemClick(AdapterView父级,视图视图,int位置,长id){

                Intent newActivity = new Intent(view.getContext(), Place.class);     
                启动活动(新活动);

            }
          });
    }

}

我不知道如何实现此活动来处理 AttractionslistActivity.Class 中的操作

公共类地点扩展活动{
    私有静态最终字符串CLASSTAG = Place.class.getSimpleName();

    私有 TextView 标题;
    私有 TextView 详细信息;
    私有 TextView …

android view settext simplecursoradapter android-cursoradapter

6
推荐指数
1
解决办法
3513
查看次数

SimpleCursorAdapter和CursorAdapter

我想知道CursorAdapter和SimpleCursorAdapter之间有什么区别.基于什么标准,某人会选择其中一个.您与他们合作的经历?谢谢

android cursor simplecursoradapter

6
推荐指数
2
解决办法
4671
查看次数

资源$ NotFoundException:资源ID #type#0x12无效

请告诉我,为什么它不喜欢我的布局(RelativeLayout with @+id/row)?

当我将它与自己创建的适配器(layoutinflater)一起使用时,效果很好.还有一个.我计划在我的数据库中使用位图,存储方式如下byte[].SimpleCursorAdapter它本身可以将byte []日期转换为图像(ImageView),还是只能用于文本?

错误说明

android.content.res.Resources$NotFoundException: Resource ID #0x7f0c006c type #0x12 is not valid
Run Code Online (Sandbox Code Playgroud)

主要活动

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mListView = ( (ListView) findViewById (R.id.notes_listView) );
    mNoteDb = new NoteDb (getApplicationContext ());
    Cursor c = mNoteDb.getTitleColumn ();

    SimpleCursorAdapter mAdapter = new SimpleCursorAdapter (getApplicationContext (),
            R.id.row, // **<<< THIS ONE**
            c, new String[]{NoteDb.MainTable.COLUMN_TITLE}, new int[]{R.id.title_text_row}, 0);
    mListView.setAdapter (mAdapter);
Run Code Online (Sandbox Code Playgroud)

行布局

<RelativeLayout
android:id="@+id/row"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:id="@+id/date_row"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_marginRight="10sp"
    android:text="@string/main_row_tv_date" …
Run Code Online (Sandbox Code Playgroud)

android listview simplecursoradapter

6
推荐指数
1
解决办法
6249
查看次数