AdapterView onClick

时间:2013-08-07 14:51:43

标签: java android variables adapter listadapter

我已经准备好了工作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);

        }
    });

2 个答案:

答案 0 :(得分:2)

您需要添加最终修饰符:

final String externalText = "Hello world.";

答案 1 :(得分:1)

final String externalText = "Hello world.";

应该这样做。