简体   繁体   English

LoadManager,SimpleCursorAdapter,ViewBinder-没有URI?

[英]LoadManager, SimpleCursorAdapter, ViewBinder - no URI?

I am trying to implement LoaderManager since its taking a while to load the rows into my ListView. 我正在尝试实现LoaderManager,因为它需要一些时间才能将行加载到ListView中。 All of the examples I have found online keep referring to a CONTENT_URI - something which I don't have. 我在网上找到的所有示例都一直在引用CONTENT_URI-我没有。

Here's my old code for loading my ListView content: 这是我用于加载ListView内容的旧代码:

  @Override
  public void onCreate( Bundle savedInstanceState )
  {
  ...
    String path = "/sdcard/mytunesdb.sqlite";   // Warning, yes, I know..

    db = SQLiteDatabase.openDatabase( path, null, 0 );

    lvCustomList = (ListView) findViewById( R.id.lv_custom_list );

    String[] columns = new String[] { "Name" };

    // THE XML DEFINED VIEWS FOR EACH FIELD TO BE BOUND TO
    int[] to = new int[] { R.id.lv_tune };  

    Cursor c = db.rawQuery( "SELECT rowid _id, Name FROM Tune ORDER BY Name", null );

    cAdapter = new MySimpleCursorAdapter( this, R.layout.like_hate_row, c, columns, to, 0 );

    viewBinder = new CustomViewBinder();

    cAdapter.setViewBinder( (ViewBinder) viewBinder );

    lvCustomList.setAdapter( cAdapter );

OK, so I start implementing the LoaderManager callbacks after changing the above code so that the cAdapter is created with null projection (null instead of 'columns' parameter). 好的,因此我在更改上述代码后开始实现LoaderManager回调,以便使用空投影(空值而不是'columns'参数)创建cAdapter。 This is how I far I get.. How do I put my rawQuery into the onCreateLoader method? 这就是我所得到的。.如何将rawQuery放入onCreateLoader方法中?

  @Override
  public Loader<Cursor> onCreateLoader(int id, Bundle args) 
  {
    String[] columns = new String[] { "Name" };

!!! HELP - I don't have a CONTENT_URI - my database is external - what do I put below?   
    CursorLoader cursorLoader = new CursorLoader( getActivity(),
              TutListProvider.CONTENT_URI, columns, null, null, null);

     return cursorLoader;
  }

  @Override
  public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) 
  {
    cAdapter.swapCursor( cursor );
  }

  @Override
  public void onLoaderReset(Loader<Cursor> loader) 
  {
    cAdapter.swapCursor( null );
  }

Do I need to keep the URI code and implement a ContentProvider for my SQL database instead?? 我是否需要保留URI代码并为我的SQL数据库实现ContentProvider?

I figured this out with the help of SimpleCursorLoader mentioned in other StackOverlow posts. 我在其他StackOverlow帖子中提到的SimpleCursorLoader的帮助下找到了答案。 I have new problems, but at the below link you will find my solution. 我遇到了新问题,但是在下面的链接中您将找到我的解决方案。

My Solution 我的解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM