1

In my application i have to display a listview and below to that i have to display a textview.Is it possible to have listview and textview in the same layout? My code is as follows:

  setContentView(R.layout.report);  
     ListView lv=(ListView)findViewById(R.id.listView1);
     db.open();
     Cursor c = db.getAllTitles();
     startManagingCursor(c);    
     String[] from = new String[] { db.KEY_INCOME,db.KEY_DESC};
     int[] to = new int[] { R.id.textView1 ,R.id.textView2};
     SimpleCursorAdapter notes =
                new SimpleCursorAdapter(this, R.layout.report, c, from, to);
//     System.out.println("notes="+notes.getCount());
     lv.setAdapter(notes);
    String total=  db.add();   

Actually i am displaying 2 textviews to display data in the list and finally i have to add 3rd textview to show thw total,if i put relative layout this listview is coming properly overriding one over the other.My Xml file as follows:

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

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
   />
<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
   /> 
<ListView
    android:id="@+id/listView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"        
    >
</ListView>  

Anybody please help me.Thanks in advace.

subburaj
  • 161
  • 2
  • 15
  • Yes you can do this. What are you displaying on screen? And what you want to do? – Krishna Suthar May 22 '12 at 05:29
  • u can use custom adapter like this http://www.ezzylearning.com/tutorial.aspx?tid=1763429&q=customizing-android-listview-items-with-custom-arrayadapter – Aamirkhan May 22 '12 at 05:40

4 Answers4

0

yes its possible, but whenever list size get exceeds the screen height, you would never be able to see textview. so instead of adding views into LinearLayout add These views into RelativeLayout, setting ListView height to fill parent, and above of text view. and TextView's alignment in parent bottom.

jeet
  • 29,001
  • 6
  • 52
  • 53
0

You can have place a text view at the bottom of the screen and the have the list view take up the entire space between the top of the screen and the textview at the bottom

This layout should do the trick:

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

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"/>

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_above="@id/textView1"/>
</RelativeLayout>
DanielGrech
  • 1,402
  • 12
  • 16
0

yes u can use Textview below Listview give Some padding using Layout margin bottom to listview and add your Textview below the Listview.so for this use RelativeLayout

Thamilvanan
  • 375
  • 3
  • 12
0

Use Linearlayout instead of Realitivelayout and set the orientation is "vertical"

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

<your textview/>
<your textview/>   

<your listview/>
<your textview with proper id/>

</LinearLayout>
Raghu Mudem
  • 6,793
  • 13
  • 48
  • 69
  • AS i followed your code total is coming at every data.But i want is total should come at the end of the list only.. – subburaj May 22 '12 at 06:21
  • your are asking about design or java logic? – Raghu Mudem May 22 '12 at 06:28
  • for design just move the third textview to below of listview. We con't help you in your java code why because we don't know your exact requirement. – Raghu Mudem May 22 '12 at 06:45
  • I tried for that also its not working..K i will explain my scenario here..In my database ,there is one table with cloumnames(income,description).In my layout i displayed this database in a list view using 2 texttviews(i have given the code in my question).Now after that displaying listview,now i want to display the total of the income column in a textview which should be below the listview.Now i got the total,but i cant dispaly that in a textview.If i use linear layout means total is coming at every data in list view.,suppose i use relative layout means,the data is overriding each other. – subburaj May 22 '12 at 06:56
  • I think you are using a custom list with 2 textview. one for income and another for description. Now you want grand total of income to assing for textview which should be below the listview. Dont take another text view in your report.xml file. just take a textview below the list view and get that id correctly and assign the value what you want. – Raghu Mudem May 22 '12 at 07:13
  • How can i get the textview below the listview.From where i can take in the design page. – subburaj May 22 '12 at 07:17
  • i cant get u clearly.What u r saying is that i have to get the id,without getting it from design page how can i get the id.With proper id means,where i can get that id.. – subburaj May 22 '12 at 07:31
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/11562/discussion-between-subburaj-and-raghu-rami-reddy) – subburaj May 22 '12 at 09:00
  • hi tried that also again it shows that total in below in every item of the list. – subburaj May 22 '12 at 09:05