SQLite 데이터베이스에서 데이터를로드하는 listView가 있는데 지금은 목록에 onclicklistener를 구현하고 싶습니다. 사용자가 목록을 클릭하면 텍스트를 다음 활동으로 가져와 해당 데이터를 TextView에로드해야합니다. 내 질문은 어떻게 목록의 데이터를 전달할 것인가입니다. 예를 들어 "주제"목록이고 사용자는 "내 집"항목을 클릭합니다. "My Home"항목을 다음 활동으로 전달하여 각 해당 데이터를 검색 할 수 있는지 확인합니다.안드로이드가 SQLite 데이터베이스의 데이터를 다음 액티비티로로드합니다.
어떻게 해결할 수 있습니까? 나는 새로운 의도에 "엑스트라를"넣을 수 있습니까? 또는 다른 방법이 있습니다.
ListView listContent = (ListView) findViewById(R.id.contentlist);
mySQLiteAdapter = new SQLiteAdapter(this);
mySQLiteAdapter.openToRead();
Cursor cursor = mySQLiteAdapter.queueAll();
startManagingCursor(cursor);
String[] from = new String[] { SQLiteAdapter.KEY_CONTENT };
int[] to = new int[] { R.id.text };
SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this, R.layout.listrow, cursor, from, to);
listContent.setAdapter(cursorAdapter);
mySQLiteAdapter.close();
//Onclick ListView setlistener
listContent.setTextFilterEnabled(true);
listContent.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent summaryIntent = new Intent(DocumentListActivity.this, ViewDocumentActivity.class);
// summaryIntent.putExtra("SummTopic", value);
}
});
편집 : : 아래 목록보기를 표시 내 코드의 일부 이 제품은 또한 다음 활동에 있습니다.
android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 0
이 도와주세요 : 데이터베이스에서 검색하는 동안
Intent i = getIntent();
extraTopic = i.getStringExtra("SummTopic");
mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null);
Cursor allrows = mydb.rawQuery("SELECT * FROM "+ TABLE + " WHERE topic = \" " + extraTopic + " \" " , null);
Integer cindex = allrows.getColumnIndex("topic");
Integer cindex1 = allrows.getColumnIndex("text1");
Integer cindex2 = allrows.getColumnIndex("text2");
나는 오류를 얻었다.
감사합니다.
안녕하세요, 도움이됩니다. 감사. 하지만 다음 활동에서 검색하는 동안 오류가 있습니다. 위 코드를 편집 된 부분에서 참조 할 수있게 도와 주시겠습니까? 덕분에 – mellissa
나는 대답을 바꿨다 – Selvin
완벽하게 작동합니다. 무리 감사! – mellissa