ListView and wrap_content

Posted by gaiapac on Stack Overflow See other posts from Stack Overflow or by gaiapac
Published on 2012-11-16T21:56:30Z Indexed on 2012/11/16 23:00 UTC
Read the original article Hit count: 153

Filed under:
|
|

I want to create an activity with a ListView on the left and a TextView on the right, side by side. I write the following xml, but the ListView occupies the entire page and it don't worry about the wrap_content. Why? How can I resolve it?

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

    <ListView 
        android:id="@+id/lv"
        android:layout_width="wrap_content"
        android:layout_height="match_parent" />

    <TextView 
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="match_parent" />

</LinearLayout>

EDIT: my onCreate

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ListView lv = (ListView) findViewById(R.id.lv);
    String[] values = new String[] { "Test1", "Test2", "Test3", "Test4" };
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.left, R.id.tv1, values);
    lv.setAdapter(adapter); 
}

© Stack Overflow or respective owner

Related posts about android

Related posts about Xml