0
我产生了ListView
所看到如下从按钮获得点击每一行中的ListView
我没有足够的代表,发布图片,你将不得不破译我的网址:image
的蓝色行上述图像中的被填充使用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>
当上述图像中的绿色按钮后,我还想得到蓝色行的信息。
(日期,描述,NUM1,NUM2)
另外,如果你想有一个更好的方式来填充ListView
,请让我知道。
对不起,但你完全失去了我。没有在代码中看到这一点,我不知道如何设置它。我试着跟随你的每一个链接并把代码放在一起,但它看起来像弗兰肯斯坦。 – gatzkerob 2012-04-15 05:33:34
有没有简单的方法来做到这一点?我在一行中有一个线性布局,当点击线性布局时,我想获得行信息。 – gatzkerob 2012-04-15 23:38:49
我没有完成你所建议的所有内容,但是我扩展了'BaseAdapter'并发现了它的特性的缺点。谢谢。 – gatzkerob 2012-05-01 03:48:39