2010-07-03 89 views
2

我为我的应用程序使用以下main.xml。ListView将不会再显示

<?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:id="@+id/toplinear"> 
    <LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/linear"> 
     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Previous" 
      android:id="@+id/previous" 
      android:layout_weight="1" 
      /> 
     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Next" 
      android:id="@+id/next" 
      android:layout_toRightOf="@id/previous" 
      android:layout_weight="1" 
      /> 
    </LinearLayout> 
    <ListView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/android:list" 
     android:layout_weight="10" 
     /> 

</LinearLayout> 

我想要在顶部,上一个和下一个按钮,以及我的列表视图与下面的自定义适配器。几天前,我只有我的ListView显示,检查按钮。现在我似乎被卡在另一边,在我的按钮的时候,我的列表视图不显示。

我的活动在ListActivity上进行扩展,并使用此代码将其填充到customadapter中。

ListView lv = getListView(); 
lv.setAdapter(new MyCustomAdapter(this, R.layout.custom_list, nameResults)); 

    public class MyCustomAdapter extends ArrayAdapter<String> { 
     private String[] nameResults; 
     private Context context; 

     public MyCustomAdapter(Context context, int textViewResourceId, 
       String[] names) { 
      super(context, textViewResourceId, names); 
      this.context = context; 
      nameResults = names; 
     } 

     @Override 
     public View getView(int position, View convertView, ViewGroup parent) { 
      View row = convertView; 
      if (row == null) { 
       LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
       row = inflater.inflate(R.layout.custom_list, parent, false); 
      } 

      TextView label = (TextView) row.findViewById(R.id.Name); 
      label.setText(nameResults[position]); 
      TextView descr = (TextView) row.findViewById(R.id.Description); 
      descr.setText(linkedResults.get(nameResults[position])); 

      return row; 
     } 
    } 

我试过使用“lv.addHeaderView(previous);”但是这只会给我关于LayoutParams的模糊的ClassCastExceptions。

我想我的问题目前在我的main.xml中,因为它的Eclipse中的布局选项卡不会显示ListView。它知道它在大纲标签中显示的位置,但是当我选择它时,可视化表示不会给它一个红色轮廓。

为了完整起见,我custom_list(又名行)布局的xml:

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#ffffff" 
> 
    <TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/Name" 
    android:textColor="#000000" 
    android:textStyle="bold" 
    /> 
    <TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/Description" 
    android:textColor="#000000" 
    /> 

</LinearLayout> 

回答

2

我修改了main.xml中一点 - 增加方向和起飞为ListView的layout_weight - 希望这解决了问题。

<?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" 
    android:id="@+id/toplinear"> 
    <LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:id="@+id/linear"> 
     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Previous" 
      android:id="@+id/previous" 
      android:layout_weight="1" 
      /> 
     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Next" 
      android:id="@+id/next" 
      android:layout_toRightOf="@id/previous" 
      android:layout_weight="1" 
      /> 
    </LinearLayout> 
    <ListView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/android:list" 
     /> 

</LinearLayout> 
+0

这似乎已经修复它,谢谢!介意给我一个这个问题upvote?需要更多的代表,所以我可以upvote你以及! :D – Rvthof 2010-07-03 23:11:08

+0

不客气 - 投票完成。 – xil3 2010-07-03 23:58:47