English 中文(简体)
• 如何为一系列的表流创建内容提供者URI,而不是完整的表格
原标题:How to create a content provider URI for a range of table rows, instead of full table
  • 时间:2012-05-12 21:57:19
  •  标签:
  • android
  • uri

我拥有一个包含多个表格的SQite数据库的内容提供器,并使用URI这样的软件:

Uri.parse("content://" + AUTHORITY + "/" + TABLE_NAME);

这似乎是标准模式,1 URI到1数据库表,1 CONTENT_。 缩略语

然而,我需要获得表格数据子的URIs。 目前,在我的数据库中增加一个附加表格,对我来说是没有意义的。 看起来像内容提供人打算这样做一样,我只能看到这一点。 基本上,我想有一个URI,它要提出一个问题,而不是一个表格。 希望是有意义的。

最佳回答

在您提出申请后,只要需要新的国际独立评估报告,你就应当修改其内容提供者的询问方法:

public class ExampleProvider extends ContentProvider {

    private static final UriMatcher sUriMatcher;


    sUriMatcher.addURI("com.example.app.provider", "table3", 1);
    sUriMatcher.addURI("com.example.app.provider", "table3/#", 2);
    sUriMatcher.addURI("com.example.app.provider", "table3/customquery", 3);

public Cursor query(
    Uri uri,
    String[] projection,
    String selection,
    String[] selectionArgs,
    String sortOrder) {

    switch (sUriMatcher.match(uri)) {


        // If the incoming URI was for all of table3
        case 1:

            if (TextUtils.isEmpty(sortOrder)) sortOrder = "_ID ASC";
            break;

        // If the incoming URI was for a single row
        case 2:

            /*
             * Because this URI was for a single row, the _ID value part is
             * present. Get the last path segment from the URI; this is the _ID value.
             * Then, append the value to the WHERE clause for the query
             */
            selection = selection + "_ID = " uri.getLastPathSegment();
            break;
        case 3:
             // handle your custom query here

             break;

    }
    // call the code to actually do the query
}
问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签