【发布时间】:2011-07-12 06:06:07
【问题描述】:
大家好,我已经找了几个小时试图找到解决方案,我的目标是让 Listview 在打开时打开另一个活动。好吧,实际上我让它能够在单击时打开另一个活动,但是我如何获得它以便每个列表项都打开自己的活动?如果这个问题已经得到回答,但我发现的链接并没有真正描述代码在做什么,我感到非常抱歉[是的,我是新手 :)]
这是我使用的代码
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] countries = getResources().getStringArray(R.array.countries_array);
setListAdapter(new ArrayAdapter<String>(this, R.layout.newfile, countries));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Intent myIntent = new Intent(view.getContext(), Html_file.class);
startActivityForResult(myIntent, 0);
}
});
}
}
【问题讨论】: