각 ListItem에 2 개의 TextView가있는 ListView가 있습니다. ListItem 클릭 할 때 해당 TextViews 값을 다른 활동에 전달하고 싶습니다. 내 모든 시도는 실패했습니다. 그래서 어떻게 할 수 있습니까? SQLite ROW_ID, R.id.text1 및 R.id.text2 값을 어떻게 전달할 수 있습니까?ListView에서 다른 액티비티로 데이터 전달하기
Cursor cursor = database.getAllNames();
adapter = new SimpleCursorAdapter(this, R.layout.listrow, cursor,
new String[] { Database.KEY_DATE , Database.KEY_NAME },
new int[] {R.id.text1, R.id.text2}, 0);
listView = (ListView) findViewById(R.id.list);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(SendingData.this, ReceivingData.class);
intent.putExtra("id", id); //this should pass the SQLite ROW_ID
intent.putExtra("date", date); //this should pass the value of R.id.text1
intent.putExtra("name", name); //this should pass the value of R.id.text2
startActivity(intent);
}
});
하지만 그것은 전체 칼럼을 통과합니다. 그렇죠? 선택한 항목의 데이터 만 전달하려고합니다. – user1617102
예, 커서를 제대로 설정하지 않았기 때문일 수 있습니다. 모든 행을 검색하는 데 익숙했을 수도 있으므로 전체 열을 전달하는 것입니다. – Swayam
업데이트 된 답변을 확인하십시오. onItemClick 내에서 커서를 사용하여 해당 행만 검색하는 코드를 추가했습니다. – Swayam