麻烦正确填写列表视图 [英] Trouble to fill listview correctly
本文介绍了麻烦正确填写列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从网上,而它与JSoup在AsyncTask的分析得到了一些数据。
我无法正确填写列表视图。
EDIT1仅被填充空字段(..)和最后行具有价值€0,00。
EDIT2没有得到填补的。
.. edit2Text
.. edit2Text
.. edit2Text
€0,00 edit2Text
€0,00 edit2Text
这两个编辑在一个的test.xml:
<?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=横向><的EditText
安卓的inputType =textMultiLine
机器人:ID =@ + ID / editText1
机器人:layout_height =WRAP_CONTENT
机器人:文字=EDIT1
机器人:layout_width =200dp
/><的EditText
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =110dp
机器人:ID =@ + ID / editText2
机器人:文字=EDIT2
安卓的inputType =textMultiLine
机器人:layout_marginLeft =10dp
/>< / LinearLayout中>
在ListView应该是这样的:
Einddatum合同:2012年8月10日
€38,50 / MND:每maand Prijs
...
我赶上地图和MAP1,看他们是否被正确填写,他们做什么,我做错了?
10月10日至22日:35:21.698:我/的System.out(8132):哈希映射:{COL_1 = Einddatum契约:}
10月10日至22日:35:21.698:我/的System.out(8132):哈希映射:{COL_1 = Prijs每maand:}
10月10日至22日:35:21.698:我/的System.out(8132):哈希映射:{COL_1 = Einddatum契约:}
10月10日至22日:35:21.698:我/的System.out(8132):哈希映射:{COL_1 = Prijs每maand:}
10月10日至22日:35:21.698:我/的System.out(8132):哈希映射:{COL_1 =的Nieuw beltegoed:}
10月10日至22日:35:21.698:我/的System.out(8132):哈希映射:{COL_1 = Tegoed vorige periode:}
10月10日至22日:35:21.708:我/的System.out(8132):哈希映射:{COL_1 = Tegoed TOT 2011年9月11日:}
10月10日至22日:35:21.708:我/的System.out(8132):哈希映射:{COL_1 =}
10月10日至22日:35:21.708:我/的System.out(8132):哈希映射:{COL_1 = Verbruik sinds的Nieuw tegoed:}
10月10日至22日:35:21.708:我/的System.out(8132):哈希映射:{COL_1 = Ongebruikt tegoed:}
10月10日至22日:35:21.708:我/的System.out(8132):哈希映射:{COL_1 = Verbruik范博文bundel:}
10月10日至22日:35:21.708:我/的System.out(8132):哈希映射:{COL_1 = Verbruik DAT Niet的在去bundel青春痘*:}
10月10日至22日:35:21.718:我/的System.out(8132):Hashmap1:{COL_2 = 2012年8月10日}
10月10日至22日:35:21.718:我/的System.out(8132):Hashmap1:{COL_2 =€38,50 / MND}
10月10日至22日:35:21.718:我/的System.out(8132):Hashmap1:{COL_2 = 2012年8月10日}
10月10日至22日:35:21.718:我/的System.out(8132):Hashmap1:{COL_2 =€38,50 / MND}
10月10日至22日:35:21.718:我/的System.out(8132):Hashmap1:{COL_2 =€54,64}
10月10日至22日:35:21.718:我/的System.out(8132):Hashmap1:{COL_2 =€17,28}
10月10日至22日:35:21.718:我/的System.out(8132):Hashmap1:{COL_2 =€71,92}
10月10日至22日:35:21.718:我/的System.out(8132):Hashmap1:{COL_2 =}
10月10日至22日:35:21.718:我/的System.out(8132):Hashmap1:{COL_2 =€5,32}
10月10日至22日:35:21.718:我/的System.out(8132):Hashmap1:{COL_2 =€66,60}
10月10日至22日:35:21.718:我/的System.out(8132):Hashmap1:{COL_2 =€0,00}
10月10日至22日:35:21.718:我/的System.out(8132):Hashmap1:{COL_2 =€0,00}
我的code:
@覆盖
保护无效onPostExecute(字符串结果){
//创建网格项映射
ListView控件KP =(ListView控件)findViewById(R.id.kpn); 的String [] =由新的String [] {COL_1,COL_2};
INT []为= INT新[] {R.id.editText1,R.id.editText1}; 清单<&HashMap的LT;字符串,字符串>> fillMaps =新的ArrayList<&HashMap的LT;字符串,字符串>>();
HashMap的<字符串,字符串>地图=新的HashMap<字符串,字符串>();
HashMap的<字符串,字符串> MAP1 =新的HashMap<字符串,字符串>();
文档的DOC = Jsoup.parse(KPN);
元件tdsFromSecondColumn = doc.select(table.personaltable TD:当量(0));
元件tdsFromSecondColumn1 = doc.select(table.personaltable TD:当量(1)); 对于(元tdFromSecondColumn:tdsFromSecondColumn){
map.put(COL_1,tdFromSecondColumn.text());
fillMaps.add(地图); 的System.out.println(哈希映射:+地图); }
对于(元tdFromSecondColumn1:tdsFromSecondColumn1){
map1.put(COL_2,tdFromSecondColumn1.text());
fillMaps.add(MAP1); 的System.out.println(Hashmap1:+ MAP1);
} SimpleAdapter适配器=新SimpleAdapter(AndroidLogin.this,fillMaps,R.layout.test,从,到);
kp.setAdapter(适配器);
解决方案
试试这个,
@覆盖
保护无效onPostExecute(字符串结果){
//创建网格项映射
ListView控件KP =(ListView控件)findViewById(R.id.kpn); 的String [] =由新的String [] {COL_1,COL_2};
INT []为= INT新[] {R.id.editText1,R.id.editText2}; 清单<&HashMap的LT;字符串,字符串>> fillMaps =新的ArrayList<&HashMap的LT;字符串,字符串>>();
清单<&HashMap的LT;字符串,字符串>> fillMaps1 =新的ArrayList<&HashMap的LT;字符串,字符串>>();
清单<&HashMap的LT;字符串,字符串>> fill_Maps =新的ArrayList<&HashMap的LT;字符串,字符串>>(); HashMap的<字符串,字符串>地图;
HashMap的<字符串,字符串> MAP1;
文档的DOC = Jsoup.parse(KPN);
元件tdsFromSecondColumn = doc.select(table.personaltable TD:当量(0));
元件tdsFromSecondColumn1 = doc.select(table.personaltable TD:当量(1)); 对于(元tdFromSecondColumn:tdsFromSecondColumn){ 地图=新的HashMap<字符串,字符串>();
map.put(COL_1,tdFromSecondColumn.text());
fillMaps.add(地图); 的System.out.println(哈希映射:+地图); }
对于(元tdFromSecondColumn1:tdsFromSecondColumn1){
MAP1 =新的HashMap<字符串,字符串>(); map1.put(COL_2,tdFromSecondColumn1.text());
fillMaps1.add(MAP1); 的System.out.println(Hashmap1:+ MAP1);
} 的for(int i = 0; I< fillMap.size();我++){ fill_Map.add(fillMap.get(I));
fill_Map.add(fillMap1.get(I));
}
SimpleAdapter适配器=新SimpleAdapter(AndroidLogin.this,fill_Map,R.layout.test,从,到);
kp.setAdapter(适配器);
和让我知道发生什么事。
I am getting some data from the net, which gets parsed with JSoup in a AsyncTask.
I am having trouble filling the listview correctly.
Edit1 only gets filled with empty fields (..) and the last rows have the value € 0,00. Edit2 does not get filled at all.
.. edit2Text
.. edit2Text
.. edit2Text
€ 0,00 edit2Text
€ 0,00 edit2Text
Both Edits are in a test.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<EditText
android:inputType="textMultiLine"
android:id="@+id/editText1"
android:layout_height="wrap_content"
android:text="edit1"
android:layout_width="200dp"
/>
<EditText
android:layout_height="wrap_content"
android:layout_width="110dp"
android:id="@+id/editText2"
android:text="edit2"
android:inputType="textMultiLine"
android:layout_marginLeft="10dp"
/>
</LinearLayout>
The listview should look like this:
Einddatum contract: 08-10-2012
Prijs per maand: € 38,50 /mnd
...
I catch map and map1 to see if they are filled correctly and they do, what i am doing wrong?
10-22 10:35:21.698: I/System.out(8132): Hashmap: {col_1=Einddatum contract:}
10-22 10:35:21.698: I/System.out(8132): Hashmap: {col_1=Prijs per maand:}
10-22 10:35:21.698: I/System.out(8132): Hashmap: {col_1=Einddatum contract:}
10-22 10:35:21.698: I/System.out(8132): Hashmap: {col_1=Prijs per maand:}
10-22 10:35:21.698: I/System.out(8132): Hashmap: {col_1=Nieuw beltegoed:}
10-22 10:35:21.698: I/System.out(8132): Hashmap: {col_1=Tegoed vorige periode:}
10-22 10:35:21.708: I/System.out(8132): Hashmap: {col_1=Tegoed tot 09-11-2011:}
10-22 10:35:21.708: I/System.out(8132): Hashmap: {col_1=}
10-22 10:35:21.708: I/System.out(8132): Hashmap: {col_1=Verbruik sinds nieuw tegoed:}
10-22 10:35:21.708: I/System.out(8132): Hashmap: {col_1=Ongebruikt tegoed:}
10-22 10:35:21.708: I/System.out(8132): Hashmap: {col_1=Verbruik boven bundel:}
10-22 10:35:21.708: I/System.out(8132): Hashmap: {col_1=Verbruik dat niet in de bundel zit*:}
10-22 10:35:21.718: I/System.out(8132): Hashmap1: {col_2=08-10-2012}
10-22 10:35:21.718: I/System.out(8132): Hashmap1: {col_2=€ 38,50 /mnd}
10-22 10:35:21.718: I/System.out(8132): Hashmap1: {col_2=08-10-2012}
10-22 10:35:21.718: I/System.out(8132): Hashmap1: {col_2=€ 38,50 /mnd}
10-22 10:35:21.718: I/System.out(8132): Hashmap1: {col_2=€ 54,64}
10-22 10:35:21.718: I/System.out(8132): Hashmap1: {col_2=€ 17,28}
10-22 10:35:21.718: I/System.out(8132): Hashmap1: {col_2=€ 71,92}
10-22 10:35:21.718: I/System.out(8132): Hashmap1: {col_2=}
10-22 10:35:21.718: I/System.out(8132): Hashmap1: {col_2=€ 5,32}
10-22 10:35:21.718: I/System.out(8132): Hashmap1: {col_2=€ 66,60}
10-22 10:35:21.718: I/System.out(8132): Hashmap1: {col_2=€ 0,00}
10-22 10:35:21.718: I/System.out(8132): Hashmap1: {col_2=€ 0,00}
My code:
@Override
protected void onPostExecute(String result) {
// create the grid item mapping
ListView kp = (ListView)findViewById(R.id.kpn);
String[] from = new String[] {"col_1", "col_2"};
int[] to = new int[] { R.id.editText1, R.id.editText1 };
List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
HashMap<String, String> map1 = new HashMap<String, String>();
Document doc = Jsoup.parse(kpn);
Elements tdsFromSecondColumn = doc.select("table.personaltable td:eq(0)");
Elements tdsFromSecondColumn1 = doc.select("table.personaltable td:eq(1)");
for (Element tdFromSecondColumn : tdsFromSecondColumn) {
map.put("col_1", tdFromSecondColumn.text());
fillMaps.add(map);
System.out.println("Hashmap: " + map);
}
for (Element tdFromSecondColumn1 : tdsFromSecondColumn1) {
map1.put("col_2", tdFromSecondColumn1.text());
fillMaps.add(map1);
System.out.println("Hashmap1: " + map1);
}
SimpleAdapter adapter = new SimpleAdapter(AndroidLogin.this, fillMaps, R.layout.test, from, to);
kp.setAdapter(adapter);
解决方案
Try this,
@Override
protected void onPostExecute(String result) {
// create the grid item mapping
ListView kp = (ListView)findViewById(R.id.kpn);
String[] from = new String[] {"col_1", "col_2"};
int[] to = new int[] { R.id.editText1, R.id.editText2 };
List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
List<HashMap<String, String>> fillMaps1 = new ArrayList<HashMap<String, String>>();
List<HashMap<String, String>> fill_Maps = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map;
HashMap<String, String> map1;
Document doc = Jsoup.parse(kpn);
Elements tdsFromSecondColumn = doc.select("table.personaltable td:eq(0)");
Elements tdsFromSecondColumn1 = doc.select("table.personaltable td:eq(1)");
for (Element tdFromSecondColumn : tdsFromSecondColumn) {
map = new HashMap<String, String>();
map.put("col_1", tdFromSecondColumn.text());
fillMaps.add(map);
System.out.println("Hashmap: " + map);
}
for (Element tdFromSecondColumn1 : tdsFromSecondColumn1) {
map1 = new HashMap<String, String>(); map1.put("col_2", tdFromSecondColumn1.text());
fillMaps1.add(map1);
System.out.println("Hashmap1: " + map1);
}
for (int i=0;i<fillMap.size();i++) {
fill_Map.add(fillMap.get(i));
fill_Map.add(fillMap1.get(i));
}
SimpleAdapter adapter = new SimpleAdapter(AndroidLogin.this, fill_Map, R.layout.test, from, to);
kp.setAdapter(adapter);
And let me know what happen..
这篇关于麻烦正确填写列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文