-1

ICSで動作するXperiaを使用しています。これは、コンテンツ プロバイダーの動作を理解する方法として私が作成したアプリです。アプリケーションは GingerBread エミュレーターで正常に動作しますが、私の電話には何も表示されません。アプリがこのように動作する原因は何ですか? Android マニフェストのコードは次のとおりです。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="legacy_systems.contentprovider"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.READ_CONTACTS"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="legacy_systems.contentprovider.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

そして、レイアウト用のコード。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView 
        android:id="@+id/android:lst"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:stackFromBottom="false"
        android:transcriptMode="normal" />

    <TextView
        android:id="@+id/con_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold" />

    <TextView 
        android:id="@+id/con_id"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

最後に、Java ソース ファイルのコードです。

package legacy_systems.contentprovider;

import android.os.Bundle;
import android.view.Menu;
import android.app.ListActivity;
import android.content.CursorLoader;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;
import android.widget.CursorAdapter;
import android.widget.SimpleCursorAdapter;

public class MainActivity extends ListActivity {

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


        Uri allCont = Uri.parse("content://contacts/people");
        Cursor c;
        if(android.os.Build.VERSION.SDK_INT <11){
            c = managedQuery(allCont, null, null, null, null);
        }
        else{
            CursorLoader cl = new CursorLoader(this,
                    allCont,
                    null,
                    null,
                    null,
                    null);

            c = cl.loadInBackground();
        }
        String[] columns = new String[]{ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.Contacts._ID};
        int views[]=new int[]{R.id.con_name, R.id.con_id};
        SimpleCursorAdapter ada;

        if(android.os.Build.VERSION.SDK_INT<11){
            ada = new SimpleCursorAdapter(this, R.layout.activity_main,c, columns, views);
        }
            else
            {
                ada = new SimpleCursorAdapter(this, R.layout.activity_main,c, columns, views, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
            }
        this.setListAdapter(ada);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

}

私はその中の問題を整理することができません。前もって感謝します。

4

2 に答える 2

0

あなたは近くにいますが、まだそこにはいません。

  1. 連絡先プロバイダーのコンテンツURIとして独自に定義した定数を使用することは避けてください。
  2. android.support.v4.content.CursorLoaderでCursorLoaderのサポートライブラリ実装を使用する必要があり、managedQueryはまったく使用しないでください。
  3. CursorLoaderを正しく使用していません。http://developer.android.com/training/load-data-background/index.htmlに、サポートライブラリバージョンの使用方法を示すCursorLoaderのトレーニングクラスがあり ます。

何が起こっているのかというと、プラットフォームバージョンのHoneycomb以下でエミュレータを実行していて、それがmanagedQueryを使用しているということです。それはうまくいきます。お使いのデバイスが新しいプラットフォームバージョンを使用していて、CursorLoaderを使用しようとして、失敗している可能性があります。

あなたは正しい考えを持っています、あなたはただ正しい戦術を使う必要があります!

于 2013-02-16T00:12:40.643 に答える
0

ListView の ID を に設定します@+android:id/lst。と入力するつもりだったと思いますlist。そこを使用していなければ+、リソース コンパイラは間違いを指摘できたはずです。

于 2013-02-16T00:09:20.863 に答える