我正在将数组加载到列表视图中,当我单击列表项时,我想在同一活动中的文本视图中显示该项目。该列表当前正在加载,但单击某个项目时程序会崩溃。有什么想法为什么?
import java.util.ArrayList;
import android.app.ListActivity;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class WordList extends ListActivity {
/**
* @see android.app.Activity#onCreate(Bundle)
*
*/
//public final static String TERM_EXTRA="com.myapp._word";
//public final static String DEF_EXTRA="com.myapp._pic";
TextView selection;
ArrayList<String> words=new ArrayList<String>();
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
selection=(TextView)findViewById(R.id.selection);
Resources res=getResources();
String[] words = res.getStringArray(R.array.words);
setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,words));
}
public void onListItemClick(ListView parent, View v, int position,long id) {
selection.setText(words.get(position).toString());
}
}