启动活动在单击列表视图项后? [英] Starting an activity after a listview item is clicked?
问题描述
好了,所以我有一个应用程序有一些教程。(约20)(每啧啧只是一些文字填写的活动画面)
Okay, so I have an app with a few tutorials.(around 20) (Each tut is just some text filled in an activity screen)
我要创建的主菜单上的一个按钮,它指向包含所有教程活动的名称列表视图活动 - 按字母排序
I want to create a button on the main menu, that points to a listview activity containing the names of all the tutorial's activities - alphabetically.
不完美的导航,我知道。但我认为这是最好的快速和简单的解决方案,直到我了解更多信息。
Not perfect navigation, I know. But I think it's the best quick and easy solution till I learn more.
下面的问题:我只想说找出单击的ListView项,并把正常的onclick()开辟了相应的教程活动
Here's the problem: I just want to say find out which listview item was clicked, and put a normal onclick() which opens up the corresponding tutorial activity.
究竟怎样设置列表视图?我知道正常的onclick是如何工作的......但如何与ListView项呢?
How exactly do I set up the listview ? I know how the normal onclick works... but how to do it with a listview item ?
我来这里从 https://groups.google.com/forum/ #!论坛/ Android的开发者
它说,我们可以在这里问初学者问题,但人们似乎宁愿花了precious暂时均值。是不是真的值得吗?如果你知道请帮助我。 (A code例子将是巨大的,但任何帮助将是AP preciated)
It said we can ask beginner questions here, but people seem to rather spend their precious time being mean. Is it really worth it ? If you know pls help me out. (A code example would be great, but any help would be appreciated)
推荐答案
这个例子显示了如何初始化一个ListView名为list1的,并在布局文件中定义的水库\\布局\\ main.xml中
This example shows how to initialize a listView named list1 and defined in a layout-file res\layout\main.xml
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView list = (ListView) findViewById(R.id.list1);
String[] days = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, days);
list.setAdapter(adapter);
/**
* go to next activity for detail image
*/
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, final int position, long id) {
System.out.println(v+position);
Intent intent = new Intent(A.this, B.class);
startActivity(intent);
}
});
}
这里有两个例子:
Here are two more examples:
- Simple Listview in Android
- SQLite Example in Android
这篇关于启动活动在单击列表视图项后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!