问题描述
我产生了的ListView
所看到如下
我没有足够的代表处发布的图片,你将不得不破译我的网址:
I don't have enough rep to post images, you'll have to decipher my URL: image
的蓝色的上述图像中的行使用的HashMap
填充:
The blue rows in the above image are populated using HashMap
:
private void showListView(JSONArray rows, JSONArray totals){
final ListView list = (ListView) findViewById(R.id.historylist);
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map;
String[] titles = new String[]{"recordID","date","description","num1","num2"};
SimpleAdapter mSchedule = null;
try{
for(int i=0;i<rows.length();i++){
map = new HashMap<String, String>();
for(int n=0;n<allRows.getJSONArray(i).length();n++){
map.put(titles[n], allRows.getJSONArray(i).getString(n));
}
mylist.add(map);
}
mSchedule = new SimpleAdapter(
History.this,
mylist,
R.layout.history_row,
titles,
new int[] {R.id.textView0, R.id.textView1, R.id.textView2, R.id.textView3, R.id.textView4}
);
list.setAdapter(mSchedule);
}catch(Exception e){
Log.e("Creating ListView", e.toString());
}
}
<LinearLayout >
<LinearLayout >
<LinearLayout >
<TextView (recordID) />
<TextView (date) />
<TextView (num1) />
<TextView (num2) />
</LinearLayout>
<TextView (description) />
</LinearLayout>
<LinearLayout (When this one is clicked) >
<ImageView />
</LinearLayout>
在上面的图像中的绿色按钮后,我还想得到蓝色的行的信息。
When the green button in the above image is clicked, Id like to get the blue row information.
(日期,描述,NUM1,NUM2)
另外,如果你想有一个更好的方式来填充的ListView
,请让我知道。
Also, if you think there's a better way to populate the ListView
, please let me know.
推荐答案
您将需要通过扩展的。在 getView
方法,你需要绑定到按钮
的Click事件。我建议有 OnClickListener
的一个实例,使用 适配器视图#getPositionForView
。一旦你有用于保持被点击,那么你可以得到你的数据的按钮视图的位置。无论是通过或直接从您的数据源。
You will need to implement your own custom adapter by extending BaseAdapter
. In the getView
method you'll need to bind to that Button
's click event. I suggest having one instance of OnClickListener
and using AdapterView#getPositionForView
. Once you have the position for the view holding the button that was clicked then you can get to your data. Either via Adapter#getItem
or directly from your data source.
这篇关于获得按钮点击列表视图中的每一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!