0

私の onCreate メソッドでは、他のメソッド、つまり fillData() と fillImages を呼び出します。fillData が行うことは、Listview の行をテキストで塗りつぶし、fillImages が行に画像を配置することです。ここまでは順調ですね。明らかに、onCreate メソッドで fillData のみを呼び出すと、テキストのみが表示されます。fillImages を呼び出すだけでも同じことが起こります。

問題は、両方を呼び出すと、最後に呼び出したメソッドの内容のみが表示されることです。例:これを呼び出すと:

@Override
public void onCreate() {
    //Here is some content left away that is not important.
    fillData();
    fillImages()
}

fillImages() メソッドのコンテンツのみを取得します。

私は何を間違っていますか?以下に、私の onCreate()、fillData()、fillImages() メソッドのコードを示します。

更新: この問題を解決するにはどうすればよいですか???

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.reminder_list);
    mDbHelper = new RemindersDbAdapter(this);
    mImageHelper = new ImageAdapter(this);
    mDbHelper.open();
    mImageHelper.open();
    fillData();
    fillImages();
    registerForContextMenu(getListView());
}

//
// Fills the ListView with the data from the SQLite Database.
//
private void fillData() {
    Cursor remindersCursor = mDbHelper.fetchAllReminders();
    startManagingCursor(remindersCursor);

    // Creates an array with the task title.
    String[] from = new String[] {RemindersDbAdapter.KEY_TITLE, RemindersDbAdapter.KEY_BODY};

    // Creates an array for the text.
    int[] to = new int[] {R.id.text1, R.id.text2};

    // SimpleCursorAdapter which is displayed.
    SimpleCursorAdapter reminders = new SimpleCursorAdapter(this, R.layout.reminder_row, remindersCursor, from, to);
    setListAdapter(reminders);

}

//
// Fills the ListView with the images from the SQLite Database.
//
private void fillImages() {
    Cursor imageCursor = mImageHelper.fetchAllImages();
    startManagingCursor(imageCursor);

    // Creates an array with the image path.
    String[] fromImage = new String[] {ImageAdapter.KEY_IMAGE};

    // Creates an array for the text.
    int[] toImage = new int[] {R.id.icon};

    // SimpleCursorAdapter which is displayed.
    SimpleCursorAdapter images = new SimpleCursorAdapter(this, R.layout.reminder_row, imageCursor, fromImage, toImage);
    setListAdapter(images);
}
4

2 に答える 2

2

なぜ自分SimpleCursorAdapterが他の人を上書きするのSimpleCursorAdapterですか?

この用語をoverride誤って使用しています。メソッドのオーバーライドとは、サブクラスがそのスーパークラスで提供されるメソッドの特定の実装を提供する場合です。これはあなたが抱えている問題とはまったく関係がありません。

私は何が間違っているのですか?

コードが機能しない理由は、setListAdapter2回呼び出しているためです。2番目の呼び出しsetListAdapaterは最初のアダプターのバインドを解除してから2番目のアダプターをにバインドするためListView、最初の呼び出しはまったく役に立たなくなります。あなたListActivityListViewアダプタは1つしか持つことができません(したがって、2つのアダプタの実装を何らかの方法でマージする必要があります)。

于 2012-06-01T18:32:44.753 に答える
1

あなたはsetListAdapter両方の方法を使用して2つ設定されており、最後はsetListAdapter(images);最後のアダプタデータのみをリストに設定しています...

于 2012-06-01T17:18:41.537 に答える