目前我有一个正确填充的ListView。当点击一行时,我有这个回电:
private void registerClickCallBack() {
ListView listView = (ListView) findViewById(R.id.carsListView);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View viewClicked, int position, long id) {
Car clickedCar = myCars.get(position);
String message = "Your password \""+clickedCar.getMake() + "\" has been copied to your clipboard ";
Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(clickedCar.getMake().toString());
Intent intent = new Intent(getApplicationContext(), view_selected_item.class);
startActivityForResult(intent, 0);
TextView tv = (TextView) findViewById(R.id.asdasd); // I have made sure asdasd is really a value
tv.setText("asd"); // tv is null
}
});
}
如果注释掉这两行,则上述代码有效。
TextView tv = (TextView) findViewById(R.id.asdasd); // I have made sure asdasd is really a value
tv.setText("asd"); // tv is null
目的是让调用创建startActivityForResult所做的新视图。如何在新创建的页面上为文本字段设置值。
基本上,我问我如何将信息传递给尚未创建的视图。在本例中为view_selected_item.class
答案 0 :(得分:1)
要通过Intent传递信息,请使用额外内容。
例如intent.putExtra("key", "value")
,在您的活动中,使用getIntent().getStringExtra("key")