带有 onClick 项目的 Android ListView [英] Android ListView with onClick items
问题描述
我是一名新程序员,并且是 Android 新手.我正在使用这个例子 http://www.androidhive.info/2012/09/android-adding-search-functionality-to-listview/ 效果很好.
I'm a new programmer and new in Android. I'm using this example http://www.androidhive.info/2012/09/android-adding-search-functionality-to-listview/ and it works great.
现在我想让项目(戴尔、三星 Galaxy S3 等)调用一个函数来打开一个具有不同信息的新活动.
Now I want to make the items (Dell, Samsung Galaxy S3, etc) to call a function to open a new activity with different information each.
例如:
如果我触摸戴尔,必须出现一个新活动,向我显示有关戴尔的信息.如果我触摸三星,同样的事情.
If I touch Dell, a new Activity has to show up showing me information about Dell. If I touch Samsung, the same thing.
我用谷歌搜索但找不到任何有用的东西,有什么提示吗?我认为这是基本的,但我是新手,所以我真的不知道从哪里开始
I Googled but couldn't find anything helpfull, any hint? I think this is basic, but I'm new so I don't really know where to start
推荐答案
在您定义列表视图的活动中
In your activity, where you defined your listview
你写
listview.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?>adapter,View v, int position){
ItemClicked item = adapter.getItemAtPosition(position);
Intent intent = new Intent(Activity.this,destinationActivity.class);
//based on item add info to intent
startActivity(intent);
}
});
在您的适配器的 getItem 中编写
in your adapter's getItem you write
public ItemClicked getItem(int position){
return items.get(position);
}
这篇关于带有 onClick 项目的 Android ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!