views:

36

answers:

1

Hello!

Im trying to do a very simple thing (showing a populated listView) but im not able. My code is not working and i cant find what's wrong, so i hope someone else can help me :)

My XML where i have the listView defined:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:padding="10px">

<TextView
    android:id="@+id/descripcion"
    android:text="@string/descripcion"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"    />

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

</LinearLayout>

The Activity:

public class s_config extends Activity {

    public ArrayAdapter<String> lvAdapter;
    public ListView lv;

    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.s_config); 

      final String[] datos = new String[]{"Elem1","Elem2","Elem3","Elem4","Elem5"};

      lvAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,datos);
      lv = (ListView) findViewById(R.id.listaConfig);
      lv.setAdapter(lvAdapter);

    }
}

When i launch the app, it goes fine, the TextView of the XML is showed but no signs of the ListView... Am i missing something?

+1  A: 

In your Xml Layout has the problem:

set layout Orientation as vertical android:orientation="vertical" that make your listview visible.

Note:

If you not set the orientation its value will be horizontal as Default.

Edited layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:padding="10px"
   android:orientation="vertical">

<TextView
    android:id="@+id/descripcion"
    android:text="@string/descripcion"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"    />

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

</LinearLayout>
Praveen Chandrasekaran
Ouch! I knew i was missing some st*pid argument os something like that, but i wasn't able to find by myself :) Maybe this kind of things should be adviced with a Warning? Anyway, thank you very much :D
Kitinz