0

リストビューが表示されないというこの問題は、非常に奇妙に思えます。まず、アクティビティに関連する関数のコードを投稿させてください。

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.result);       
    mListView = (ListView)this.findViewById(R.id.wrdList);

    handleIntent(getIntent());
}

private void handleIntent(Intent intent) {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String word = intent.getStringExtra(SearchManager.QUERY);
        //use the query to search your data somehow

        //Columns to be selected in database
        String sel[] = {"_id", "wort", DictDBHelper.get2LtrLang()};
        Cursor SrhRet = mSrhHelper.searchWord(word, sel);
        //Columns to be showed in ListView
        String col[] = {"wort", DictDBHelper.get2LtrLang()};
        showList(SrhRet, col);
        SrhRet.close();
    } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {

    }
}

/*
 * Set the TextView to print how many words are found in database 
 */
protected void setCount(int count) {
    TextView tv = (TextView)this.findViewById(R.id.wrdCount);
    tv.setText(String.valueOf(count));
}

/*
 * Set the adapter to show the list
 * First parameter specifies the cursor of rows to be shown in ListView
 * Second one specifies columns
 */
protected void showList(final Cursor SrhRet, String[] from) {

    int[] to = new int[]{R.id.entry, R.id.detail};

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, 
            R.layout.listitem, SrhRet, from, to, 
            CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    mListView.setAdapter(adapter);
    setCount(mListView.getCount());

    mListView.setOnItemClickListener(new OnItemClickListener(){         
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // Build the Intent used to open WordActivity with a specific word Uri
            Intent wordIntent = new Intent(getApplicationContext(), WordActivity.class);
            Uri data = Uri.withAppendedPath(DictionaryProvider.ENTRY_CONTENT_URI,
                                            String.valueOf(id));
            wordIntent.setData(data);
            //Required by the update 
            SrhRet.close();
            mSrhHelper.updateHist(id);
            startActivity(wordIntent);
        }
    });
}

これらは、入力を searchable で処理する関数です。関連するすべての変数を追跡しましたが、異常はほとんど見つかりません。ただし、この関数を試すたびに、TextView には ListView に含まれる正しい数値が表示されます。これらの関数は以前は完全に機能していましたが、この関数から派生した別のアクティビティがこれらの関数を呼び出し、これもうまく機能します。

ListView の項目の内容として listitem.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" >
<TextView 
    android:id="@+id/entry"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:textSize="17dp" />   
<TextView 
    android:id="@+id/detail"
    android:layout_height="wrap_content"
    android:layout_width="match_parent" />

そして私のresult.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">
<TextView 
    android:id="@+id/wrdCount"
    android:layout_height="wrap_content"
    android:layout_width="match_parent" />
<ListView
    android:id="@+id/wrdList"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" />
</LinearLayout>

事前に助けてくれてありがとう!

4

1 に答える 1

0

あなたの問題はこれだと思います:SrhRet.close();あなたのhandleIntent(Intent intent)方法では。

onDestroy()アクティビティのメソッドでカーソルを閉じてみてください。

于 2012-04-12T11:34:36.047 に答える