2

I want to design listView like the this image link i have given below, https://i.stack.imgur.com/M8oQY.png, I have try all types of layout but still not able to define listview like this, please help me, my code is given below.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:background="#ffff"
android:focusable="false"
android:id="@+id/notifTable"
android:layout_height="fill_parent">

<LinearLayout
  android:layout_height="fill_parent"
  android:layout_width="wrap_content"
  android:background="#08707D"
  android:orientation="vertical"
  android:id="@+id/tableRow1">
<ImageView
    android:layout_height="60dp"
    android:layout_width="60dp"
    android:src="@drawable/alert"
    android:padding="5dp"
    /> 
 </LinearLayout>

<LinearLayout
  android:layout_width="0dp"
  android:layout_height="fill_parent"
  android:background="#08707D"
  android:layout_weight="1"
  android:orientation="vertical"
  android:id="@+id/tableRow2"
>
<TextView
  android:id="@+id/label1"
  android:layout_height="match_parent"
  android:layout_width="fill_parent"
  android:text="@string/hello_world"
  android:singleLine="true"
  android:layout_weight="0.5"
  android:textColor="@color/button"
  style="@style/listTextStyle"
       >
   </TextView>
   <TextView
     android:id="@+id/label2"
     android:layout_height="wrap_content"
     android:layout_width="fill_parent"
      android:text="@string/hello_world"
     android:singleLine="true"
      android:layout_weight="0.5"
      android:textColor="@color/button"
      >
    </TextView>

  </LinearLayout>

 </LinearLayout>
  • do you have a listview for each of this list_item_view – krishna Mar 20 '15 at 07:40
  • I add this layout with list view in my custom adapter –  Mar 20 '15 at 07:44
  • So are you not getting exactly the listview in the picture or you dont get anything at all – krishna Mar 20 '15 at 07:46
  • http://i.stack.imgur.com/UnVJL.png, I am getting the view in this way –  Mar 20 '15 at 07:53
  • The issue is that you are using a horizontal linear layout and you've set the width/height of your image view to 60dp. Your other linear layout (for the two texts) is then `adopting` this height of 60dp to show its content. Try setting the ImageView's width/height to `wrap_content` and see if that changes the way things are displayed. I would also recommend using RelativeLayout as your top-most layout and as the parent of your ImageView instead of a linear layout but that's more of a personal preference and an optimization tip. – kha Mar 20 '15 at 08:15
  • Yes thankx, i have solved it using Relative layout –  Mar 20 '15 at 08:20

2 Answers2

1

You need to add the ListView Control in your layout:

ListView is a view group that displays a list of scrollable items. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array or database query and converts each item result into a view that's placed into the list.

You have not added the listview in your layout and more ref refer this example Custom ListView Android

And also you need to update the list item linearlayout

to

<LinearLayout
        android:id="@+id/tableRow2"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="#08707D"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/label1"
            style="@style/listTextStyle"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:text="@string/hello_world"
            android:textColor="@color/button" >
        </TextView>

        <TextView
            android:id="@+id/label2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:text="@string/hello_world"
            android:textColor="@color/button" >
        </TextView>
    </LinearLayout>
Community
  • 1
  • 1
Fahim
  • 12,198
  • 5
  • 39
  • 57
0

try this

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:background="#ffff"
android:focusable="false"
android:id="@+id/notifTable"
android:layout_height="wrap_content">


<ImageView
    android:layout_height="60dp"
    android:layout_width="60dp"
    android:src="@drawable/alert"
    android:padding="5dp"
    /> 

 <LinearLayout
   android:layout_width="0dp"
   android:layout_height="wrap_content"
   android:background="#08707D"
   android:layout_weight="1"
   android:orientation="vertical"
   android:id="@+id/tableRow2"
 >
<TextView
  android:id="@+id/label1"
  android:layout_height="wrap_content"
  android:layout_width="wrap_content"
  android:text="@string/hello_world"
  android:singleLine="true"
  android:textColor="@color/button"
  style="@style/listTextStyle"
       >
   </TextView>
   <TextView
     android:id="@+id/label2"
     android:layout_height="wrap_content"
     android:layout_width="wrap_content"
      android:text="@string/hello_world"
     android:singleLine="true"
      android:textColor="@color/button"
      >
    </TextView>
krishna
  • 609
  • 8
  • 21