Samra Samra - 25 days ago 8
Android Question

Cant see the listview

I am trying to bind my listview through an array adapter. I have my listview in a layout

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>




Then I have another layout with TextView to load in the 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"/>




In my code I am doing the following but my list view has never loaded once

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);


I have also tried simple array instead of arraylist alTest but didnt work

Answer

So the problem was not that listview wasn't loading but that the imageview before it was covering more screen!! also Now i have another problem (posting on a new thread)

<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>

The image doesnot expand the whole width of screen