2011-12-26 80 views
1

我該怎麼做?我已經搜索,看了,仍然沒有發現任何有用的東西。兩行 - 列表視圖中的單個項目 - 如何?

我目前有2個arraylist。 第一個包含我從以前的活動中得到的字符串。 第二個包括上面提到的計算結果的兩倍,我從以前的練習中得到。

我已經在SQLLITE數據庫中保存了兩個Arraylists。

我走到這一步,最好的是:

裏面的onCreate:

SimpleAdapter adapter = new SimpleAdapter(this, list, 
      R.layout.custom_row_view, 
      new String[] { "operationName", "operationValue" }, new 
          int[] { R.id.text1,R.id.text2 }); 
populateList(); 
setListAdapter(adapter); 

在函數內部 - populateList(); :

static final ArrayList<HashMap<String, Double>> list = new ArrayList<HashMap<String, Double>>(); 

private void populateList() { 

HashMap<String, Double> temp = new HashMap<String, Double>(); 
for (int i = 1; i <= 20; i++) { 
    temp.put(operationNames.get(i), operationValues.get(i)); 
} 

list.add(temp); 
} 

編輯: 的custom_row_view的.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="vertical" > 

<TextView 
    android:id="@+id/tv1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textColor="#CBC300" 
    android:textSize="16sp" 
    android:textStyle="bold" /> 

<TextView 
    android:id="@+id/tv2" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textColor="#3200A3" 
    android:textSize="16sp" 
    android:textStyle="bold" /> 

</LinearLayout> 

我失去的是什麼?在輸入這個特定的列表活動時它會一直崩潰。

任何幫助將非常感激。

+0

你可以發佈你的堆棧跟蹤嗎?確定什麼是錯誤可能很有用。 – jcxavier 2011-12-26 18:10:42

+0

這裏有一個newbi的位,什麼是堆棧跟蹤? – Pisti 2011-12-26 18:13:09

+0

具有操作名稱和操作值具有更多值或至少20個值。 – 2011-12-26 18:13:51

回答

1

在您的代碼中,您嘗試從2個元素列表中獲取第三個元素!您可以將一些默認值設置爲該列表或僅顯示2個項目。

+0

謝謝,它有點幫助我認爲,仍然有很多挖掘到不過,無論如何非常感謝你! – Pisti 2011-12-26 19:39:04

相關問題