0
안드로이드 웹 사이트에서 메모장 자습서 작업 중입니다. 이름과 주소 등 2 개의 항목으로 데이터베이스를 만들었습니다. 응용 프로그램이 실행될 때 이름 만 표시됩니다. 이름과 주소를 모두 표시하고 싶습니다. filldata 메서드를 편집했지만 작동하지 않습니다. 아래 내 코드를 참조하십시오. 어떤 제안? 당신의 R.layout.notes_row
파일에서목록의 SQLite 레이아웃 변경
private void fillData() {
Cursor notesCursor = mDbHelper.fetchAllNotes();
startManagingCursor(notesCursor);
// Create an array to specify the fields we want to display in the list (TITLE + BODY)
String[] from = new String[]{NotesDbAdapter.KEY_TITLE,NotesDbAdapter.KEY_BODY};
// and an array of the fields we want to bind those fields to (in this case just text1)
int[] to = new int[]{R.id.text1};
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.notes_row, notesCursor, from, to);
setListAdapter(notes);
}
감사합니다. 내 notes_row 파일에 두 번째 textview를 만들려고 시도하는 중 오류가 계속 발생합니다. 내 코드는 아래에 나와 있습니다. 어떤 아이디어?'$ xml version = "1.0"encoding = "utf-8"?> <텍스트 뷰 로이드 : ID ="@ + ID/텍스트 2 " 로이드 : layout_width ="wrap_content " 로이드 : layout_height = "wrap_content" /> –
DMC
@ user876343 내 편집 된 답변을 참조하십시오. XML 레이아웃에서는 하나의 루트 요소 만 가져야하며,이 때문에 두 개의 TextView를 다른 요소로 래핑해야합니다 (저는 'LinearLayout'을 사용했지만 다른 옵션이 있습니다). 위의 코드를 사용하면 두 개의 'TextView'가있는 레이아웃을 다른 레이아웃 위에 배치 할 수 있습니다. – Luksprog
감사합니다. 도움에 대한 건배! – DMC