加入2按钮,文本视图 [英] Adding 2 buttons to the text view
问题描述
我试图创建一个屏幕,在这里我要的歌曲名称(保存为文本视图)的列表。
除了每个名字我想补充的2个按钮(收藏夹和篮子)。
I'm trying to create a screen where I'll have a list of song names( saved as text view). Beside each name I would like to add 2 buttons (favourites and basket).
我想有这些按钮会以某种方式链接到特定歌曲的名字,当我点击首乐曲旁的收藏夹按钮这首歌的标题将被添加到下一个活动 - >收藏夹。
每当我在篮下单击歌曲名称旁边 - 歌名将被添加到我的购物清单
I'd like to have these buttons be in some way link to the specific song name, that when I click a favourites button beside the song- this song title will be added to next activity --> Favourites. And whenever I click on basket beside the song name - the song title will be added to my shopping list.
我希望它是有意义的。
I hope it make sense.
你能不能让我知道这将是最好的呢?或者即使它是可能....
谢谢你。
Can you let me know what will be the best to do it? Or even if it is possible.... Thanks.
推荐答案
这是绝对有可能在Android的一个相当普遍的模式。你需要做的是建立一个ListView和自定义适配器的实例设置它。在适配器,你至少需要重写getView方法在列表中指定每个项目的内容。在这里,您可以添加两个按钮你的两个项目并设置其的onclick监听器(可能是适配器)。可以使用setTag到按钮的实例与该项目数据相关联。
This is definitely possible and a fairly common pattern in Android. What you need to do is create a ListView and set an instance of your custom adapter to it. In the adapter, you need to at least override the getView method to specify the contents of each item in your list. This is where you can add the two buttons two your item and set their onclick listener (possibly the adapter). You can use setTag to associate instances of the button with the item data.
下面是一个类似的问题:
<一href=\"http://stackoverflow.com/questions/1709166/android-listview-elements-with-multiple-clickable-buttons\">Android: ListView的元素有多个可单击按钮
Here is a similar question: Android: ListView elements with multiple clickable buttons
这篇关于加入2按钮,文本视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!