1

here my xml layout of my Android app (where I show all of my contacts)

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

   <TextView
       android:id="@+id/android:empty"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:layout_marginLeft="5dip"
       android:layout_marginTop="5dip"
       android:text="Scegli il contatto:"
         />

   <EditText 
       android:id="@+id/editTextSend"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"/>

   <ListView
       android:id="@+id/android:list"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content" >
   </ListView>

</LinearLayout>

I fill ListView using a custom Adapter. But textView and Edit Text are not visibile. I want to show in particular edit text where users can write initial letters of his contacts name) Suggestions to get them visible?

FrankBr
  • 886
  • 2
  • 16
  • 37
  • How many values are in your ListView? – Andy Apr 09 '13 at 18:31
  • The TextView is not shown because you used the magic id `@+id/android:empty`, so this TextView will only be visible when the ListView is empty. (I have no idea why the EditText isn't shown.) Are you calling `setContentView()` with this layout? – Sam Apr 09 '13 at 18:32
  • @Sam I have copied and pasted the above layout, Everything is visible...may be ha hasn't set ContentView in the Activity as you said – Pragnani Apr 10 '13 at 05:09
  • 1
    @Pragnani I agree, the layout is ok, I just doubt it's being used. I posted an answer explaining why oonly the ListView is visible. – Sam Apr 10 '13 at 17:57

2 Answers2

1

I fill ListView ... But textView and Edit Text are not visibile.

If you can only see a ListView then it appears you're using a ListActivity and forgot to call setContentView(). So you aren't actually using your layout... you only see ListActivity's default ListView.


That said, your XML code will work, but here are some quick notes:

  1. As I stated in my comment, the TextView might be hidden depending on what type of Activity or Fragment you are using:
    • A ListActivity will automatically bind the @+id/android:empty and @+id/android:list Views, so the "empty" TextView is only shown when the ListView is empty.
    • An Activity won't recognize @+id/android:empty on its own. All the Views should be visible.
  2. fill_parent is deprecated, simply use match_parent
  3. Setting a ListView's height to wrap_content forces the Adapter to draw the ListView multiple times... with your layout I recommend using match_parent.
Sam
  • 86,580
  • 20
  • 181
  • 179
-1

I'd say it is visible pretty fine with your layout. But anyway, I'd make listview declared that way:

<ListView
   android:id="@+id/android:list"
   android:layout_width="fill_parent"
   android:layout_height="0dp"
   android:layout_weight="1" >

so it will take all the remaining free space

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141