我正在創建一個應用程序,您可以在其中插入任務並對其進行修改。我目前可以在我創建的列表中查看任務,但是當我單擊列表時只顯示標題,但其他條目未顯示。使用SQLite填充ListView
在輸入畫面我有代碼填充與以往的信息輸入畫面:
mSaveButton = (ImageButton) findViewById(R.id.diaryform_ib_save);
Log.i(TAG,"Field Title: "+ mTitle);
Intent showTitle = getIntent();
String fieldTitle = showTitle.getStringExtra(Constants.DIARY_TITLE);
Log.i(TAG,"Field Title 2: "+ fieldTitle);
mTitle.setText(fieldTitle);
Intent showEntry = getIntent();
String fieldEntry = showEntry.getStringExtra(Constants.DIARY_ENTRY);
mEntry.setText(fieldTitle);
Log.i(TAG,"Field Entry: "+ mEntry);
Log.i(TAG,"Field Entry 2: "+ fieldEntry);
我在那裏有日誌消息,所以我可以看到的是被賦予什麼樣的信息。對於fieldTitle,將傳遞標題並傳遞fieldEntry null。當我製作fieldTitle時,這兩個字段都填充了標題。
在我的ListActivity類我有下面的代碼片段:
diaryDAO = new DAO(this); //Creates an instance of the DAO
Cursor diaryCursor = diaryDAO.queryDiary(Diary.DiaryItem.LIST_PROJECTION, null, null);
Log.i(TAG, "I get to here!");
String[] diaryDataColumns = { Diary.DiaryItem.COLUMN_NAME_DIARY_TITLE,Diary.DiaryItem.COLUMN_NAME_DIARY_ENTRY };
Log.i(TAG, "Also here");
int[] viewIDs ={ R.id.textView1 };
Log.i(TAG, "Diary Data Col" +diaryDataColumns);
Log.i(TAG, "I'm here");
//Creates backing adapter for the ListView
@SuppressWarnings("deprecation") s
SimpleCursorAdapter diaryAdapter= new SimpleCursorAdapter(
this,
R.layout.activity_diary_list,
diaryCursor,
diaryDataColumns,
viewIDs
);
Log.i(TAG, "Now im here");
this.setListAdapter(diaryAdapter);
當我創建diaryDataColumns字符串我想加入Diary.DiaryItem.COLUMN_NAME_DIARY_ENTRY,它不會進入屏幕內顯示,但是當我將Diary.DiaryItem.COLUMN_NAME_DIARY_TITLE更改爲進入列表視圖,該條目顯示給出的條目。
任何想法?對我在做什麼錯誤略有困惑。
感謝
編輯:
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Intent openItem = new Intent(this, DiaryEntryActivity.class);
Cursor listCursor = (Cursor)l.getAdapter().getItem(position);
openItem.putExtra(Constants.DIARY_TITLE, listCursor.getString(1));
startActivity(openItem); //Starts the intent actions
}
您不需要多次調用getIntent,您如何將數據作爲額外的數據添加到意圖中,從其他活動向我們展示代碼 –