2012-07-25 80 views
0

我在stackoverflow上询问了一些关于固定标题和多个数据列的问题,最后我提出了一些我认为有意义的问题,我觉得我非常接近我的目标。现在问题是数据没有得到显示。我做了log.i,我发现我成功地从我的数据库中读取,所以我想我的适配器有问题?无法显示ListView(多个数据列)

活性:

公共类HistoryActivity延伸活动 {

private static final String TAG = "HistoryActivity"; 
ListView lv; 
SimpleAdapter sd; 

RecordDAO dao = new RecordDAO(HistoryActivity.this); 

@Override 
protected void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    Log.i(TAG, "onCreate"); 

    setContentView(R.layout.historyactivityheader); 
    lv = (ListView) findViewById(R.id.list); 
    ArrayList<Record> Records = new ArrayList<Record>(); 
    Records = (ArrayList<Record>) dao.findAll(); 


    ArrayList<HashMap<String, String>> aList = new ArrayList<HashMap<String, String>>(); 
    HashMap<String, String> map; 

    for (int x = Records.size()-1; x >=0; x--) 
    { 
     map = new HashMap<String, String>(); 
     map.put("ID", String.valueOf(Records.get(x).getId())); 
     ... 

     aList.add(map); 
    } 

    sd = new SimpleAdapter(this, aList, R.layout.historyactivityrow, 
      new String[] 
      { "col1", "col2", "col3", 
        "col4" }, new int[]    
      { R.id.col1, R.id.col2, R.id.col3, 
        R.id.col4}); 


    lv.setAdapter(sd); 




} 

}

historyactivityheader.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:clickable="true" 
    android:orientation="vertical" > 


    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:clickable="true" 
     android:orientation="horizontal" 
     android:paddingBottom="6dip" 
     android:paddingTop="4dip" > 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="col1" 
      android:textColor="#FFFFFF" 
      android:textSize="16dp" /> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="col2" 
      android:textColor="#FFFFFF" 
      android:textSize="16dp" /> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="col3" 
      android:textColor="#FFFFFF" 
      android:textSize="16dp" /> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="col4" 
      android:textColor="#FFFFFF" 
      android:textSize="16dp" /> 
    </LinearLayout> 

    <ListView 
    android:id="@+id/list" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 
</ListView> 


</LinearLayout> 

historyactivityrow.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    android:paddingBottom="6dip" 
    android:paddingTop="4dip" > 

    <TextView 
     android:id="@+id/col1" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:textColor="#FFFFFF" /> 

    <TextView 
     android:id="@+id/col2" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="15dp" 
     android:layout_weight="1" 
     android:textColor="#FFFFFF" /> 

    <TextView 
     android:id="@+id/col3" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:textColor="#FFFFFF" /> 

    <TextView 
     android:id="@+id/col4" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:textColor="#FFFFFF" /> 

</LinearLayout> 

回答

0

解决方案:

答案是,头部的高度使用FILL_PARENT所以它覆盖的列表视图...这样一个愚蠢的错误... 因此,改变如下: 的header.xml应该在relativelayout,并将listview放置在headertextview下方,然后将listview的宽度设置为fill_parent,最后将header的高度更改为wrap_content