나는 2 번의 활동이 있습니다.캔트리스트 뷰에서 무작위로 데이터를 선택
첫 번째 활동은 서버의 JSON 데이터를 ListView
으로 구문 분석하는 활동이고 두 번째 활동은 ListView
에 선택된 값의 데이터를 표시하는 활동입니다.
은 여기 내 첫번째 활동의 onClick
방법입니다 :
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(this, userList,
R.layout.listitemviewall,
new String[] { "namaresto", "alamatresto"},
new int[] {R.id.name, R.id.address});
setListAdapter(adapter);
/**
* select resto
*/
final ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
/**
* move to the next activity
* */
String namanya = ((TextView) findViewById(R.id.name)).getText().toString();
String alamatnya = ((TextView) findViewById(R.id.address)).getText().toString();
//Starting a new Intent
Intent nextScreen = new Intent(getApplicationContext(), InfoTab.class);
//Sending data to another Activity
nextScreen.putExtra("name", namanya);
nextScreen.putExtra("address", alamatnya);
// starting new activity
startActivity(nextScreen);
}
});
그리고 여기에 두 번째 활동 :
TextView txtname = (TextView) findViewById(R.id.textTEST1);
TextView txtaddress = (TextView) findViewById(R.id.TextTEST2);
//displaying data from previous activity
Intent i = getIntent();
// Receiving the Data
String name = i.getStringExtra("name");
String address = i.getStringExtra("address");
// Displaying Received data
txtname.setText(name);
txtaddress.setText(address);
결과가 두 번째 활동은 항상 첫 번째 레코드를 표시합니다! 두 번째 또는 다른 레코드를 클릭 한 경우에도 ListView
.
ListView
에서 선택된 올바른 레코드를 표시하려면 어떻게해야합니까?
고맙습니다. 저에게 맞는 작품입니다! –
행복 했어요 :) – Th0rndike