2013-05-24 6 views
0

У меня есть textView, editText и listView. Я хотел бы заказать textView и editText рядом друг с другом, поэтому LinearLayout. Кроме того, создайте listView под ними. Вот XML.ListView не отображается/Android Layouts

К сожалению, listView не отображается. Я убедился, что ArrayList, который я использую, не пуст.

<RelativeLayout 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" 
    tools:context=".MainActivity" 
    android:gravity="center" 
    android:background ="#268496" > 

<LinearLayout android:id="@+id/linear" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent"> 

<TextView 
    android:id="@+id/prefixText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="#FFFFFF" 
    android:textIsSelectable="true" 
    android:textSize="12pt" 
    android:typeface="sans" /> 

<EditText 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:id="@+id/input" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:inputType="text" 
    android:textSize="12pt" 
    android:maxLength="1" 
    android:typeface="sans" /> 

</LinearLayout> 

<ListView 
    android:id="@+id/listView" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_below="@id/linear" 
    android:layout_marginBottom="10dp" 
    android:layout_marginTop="5dp" 
    android:divider="#CCCCCC" 
    android:dividerHeight="1dp" 
    android:paddingLeft="2dp" > 

    </ListView> 

</RelativeLayout> 

Создание списка:

public void listView(){ 
    ListView lv; 
    setContentView(R.layout.activity_main); 
    lv = (ListView) findViewById(R.id.listView); 
    ArrayList<String> your_array_list = new ArrayList<String>(); 
    your_array_list.add("foo"); 
    your_array_list.add("bar"); 
    ArrayAdapter<String> arrayAdapter =  
    new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, your_array_list); 
    lv.setAdapter(arrayAdapter); 

} 

ответ

3

Ваша высота Linear Макет match_parent, изменение, чтобы wrap_content

<RelativeLayout 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" 
    tools:context=".MainActivity" 
    android:gravity="center" 
    android:background ="#268496" > 

<LinearLayout android:id="@+id/linear" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 

<TextView 
    android:id="@+id/prefixText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="#FFFFFF" 
    android:textIsSelectable="true" 
    android:textSize="12pt" 
    android:typeface="sans" /> 

<EditText 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:id="@+id/input" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:inputType="text" 
    android:textSize="12pt" 
    android:maxLength="1" 
    android:typeface="sans" /> 

</LinearLayout> 

<ListView 
    android:id="@+id/listView" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_below="@id/linear" 
    android:layout_marginBottom="10dp" 
    android:layout_marginTop="5dp" 
    android:divider="#CCCCCC" 
    android:dividerHeight="1dp" 
    android:paddingLeft="2dp" > 

    </ListView> 

</RelativeLayout> 
1

вместо match_parent для LinearLayout использования wrap_content android:layout_height="wrap_content".

0

Потому что ваш LinearLayout имеет android:layout_height="match_parent", и это означает, что он будет иметь полную высоту и там не останется места для ListView.

Замените его на wrap_content.