问题描述
我是一个新的程序员,在新的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.
我用Google搜索,但没有找到任何有益的,任何暗示?我想这是基本的,但我是新,所以我真的不知道从哪里开始。
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.getItem(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);
}
这篇关于Android的ListView的使用的onClick项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!