2016-11-08 88 views
0

我想通過數組適配器綁定我的列表視圖。我有我的ListView的佈局無法查看列表視圖

activity_menu.xml

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

<TableLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <TableRow> 
     <ImageView android:layout_height="wrap_content" 
      android:layout_width = "wrap_content" 
      android:src="@drawable/saltnpepper" 
      android:layout_weight="1" 
      android:scaleType="centerInside"/> 
    </TableRow> 

    <TableRow android:paddingTop="@android:dimen/app_icon_size"><TextView></TextView></TableRow> 
<TableRow> 
    <ListView android:id="@+id/list1" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_margin="10dp"> 

    </ListView> 
</TableRow> 
</TableLayout> 

然後我有TextView的另一個佈局在ListView

menulist.xml

加載
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<TextView 
    android:id="@+id/nameText" 
    android:text="@string/app_name" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:textSize="16sp" 
    android:textStyle="bold"/> 

在我的代碼我做以下,但我的列表視圖中從來沒有一次加載

ArrayList<String> alTest = new ArrayList<String>(); 
alTest.add("One"); 
alTest.add("Two"); 

ArrayAdapter<String> catAdapter = new ArrayAdapter<String>(this, R.layout.menulist, R.id.nameText, alTest); 
ListView list = (ListView)findViewById(R.id.list1); 
list.setAdapter(catAdapter); 

我也曾嘗試簡單的數組,而不是ArrayList的alTest但沒有工作

+0

你的東西在你的'Logs'表演之謂也。 –

回答

0

所以問題不是那個listview沒有加載,但它之前的imageview覆蓋更多的屏幕!還有現在我有一個問題(張貼在一個新的線程)

<TableRow android:layout_weight="1" android:gravity="center"> 
     <ImageView android:layout_height="200dp" 
      android:layout_width = "match_parent" 
      android:src="@drawable/saltnpepper"     
      android:scaleType="centerInside" /> 
    </TableRow> 

圖像不列入擴大屏幕的整個寬度