嘿大家我已经找了几个小时试图找到解决方案,我的目标是当它打开另一个活动时有一个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);
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
nge*_*esh 18
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
if(position == 1) {
//code specific to first list item
Intent myIntent = new Intent(view.getContext(), Html_file1.class);
startActivityForResult(myIntent, 0);
}
if(position == 2) {
//code specific to 2nd list item
Intent myIntent = new Intent(view.getContext(), Html_file2.class);
startActivityForResult(myIntent, 0);
}
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21636 次 |
| 最近记录: |