由网友(上帝睡了麽)分享简介:嘿大家我已经看了好几个小时试图找到一个解决的办法,我的目标是有当它打开以及打开另一个活动的一个列表视图。嗯,事实上我得到了它能够打开另一个活动时,它的点击,但我怎么得到它使每一个列表项将开放其自己的活动?很抱歉,如果这个问题已经回答了,但我发现这个链接并不能真正说明什么code做[是的,我是一个新手:)] 这是使用co...![Linux QtFM 文件管理器的 3 个令人愉快的功能 Linux 中国](https://p.xsw88.cn/allimgs/daicuo/20230903/5872.png)
嘿大家我已经看了好几个小时试图找到一个解决的办法,我的目标是有当它打开以及打开另一个活动的一个列表视图。嗯,事实上我得到了它能够打开另一个活动时,它的点击,但我怎么得到它使每一个列表项将开放其自己的活动?很抱歉,如果这个问题已经回答了,但我发现这个链接并不能真正说明什么code做[是的,我是一个新手:)]
这是使用code IM
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的String []国家= getResources()getStringArray(R.array.countries_array)。
setListAdapter(新ArrayAdapter<字符串>(这一点,R.layout.newfile,国家));
ListView的LV = getListView();
lv.setTextFilterEnabled(真正的);
lv.setOnItemClickListener(新OnItemClickListener(){
公共无效onItemClick(适配器视图<>母公司视图中查看,
INT位置,长的id){
//单击时,显示出与TextView的文字敬酒
意图myIntent =新的意图(view.getContext(),Html_file.class);
startActivityForResult(myIntent,0);
}
});
}
}
解决方案
lv.setOnItemClickListener(新OnItemClickListener(){
公共无效onItemClick(适配器视图<>母公司视图中查看,
INT位置,长的id){
//单击时,显示出与TextView的文字敬酒
如果(位置== 1){
//具体到一个列表项code
意图myIntent =新的意图(view.getContext(),Html_file1.class);
startActivityForResult(myIntent,0);
}
如果(位置== 2){
// $ C $具体到第二个清单项目C
意图myIntent =新的意图(view.getContext(),Html_file2.class);
startActivityForResult(myIntent,0);
}
}
});
![Linux QtFM 文件管理器的 3 个令人愉快的功能 Linux 中国](https://p.xsw88.cn/allimgs/daicuo/20230903/5872.png)
Hey everyone I've looked for hours trying to find a solution to this, my goal is to have a Listview when it opens well open another activity. Well actually I got it to be able to open another activity when its click but how do I get it so that each list item will open its own activity? I am terribly sorry if this question is already answered but the links I found doesn't really describe what the code is doing [Yes i am a newbie :)]
this is the code im using
@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);
}
});
}
}
解决方案
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);
}
}
});
相关推荐
最新文章