我已经准备好工作的 ListAdapter 和 ClickListener,但我想在 ClickListener 中使用变量“externalText”,但它不起作用。我不知道我该怎么做。
String[] array = getResources().getStringArray(R.array.anyArray);
if(something == something) {
String externalText = "Hello world.";
}
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.activity_main, R.id.text, array));
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick (AdapterView<?> parent, View view, int position, long id) {
Intent i = new Intent(getApplicationContext(), Second.class);
String extraText = externalText;
i.putExtra("text",extraText);
startActivity(i);
}
});