为什么不填充listView?
问题描述:
我试图做一个非常简单的事情(显示一个填充listView),但我不能。我的代码不工作,我不能找到什么是错的,所以我希望有人能够帮助我:)为什么不填充listView?
我XML在那里我有定义列表视图:
<?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>
的活动:
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);
}
}
当我启动应用程序,它会很好,XML的TextView显示,但没有ListView的迹象...我错过了什么?
答
在你的XML布局有问题:
组布局方向为垂直android:orientation="vertical"
,让您的ListView可见。
注:
如果您没有设置导向它的价值将是水平为默认。
编辑的布局:
<?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>
哎哟!我知道我错过了一些st * pid参数,类似这样的东西,但我无法自己找到:)也许这种事情应该与警告通知?无论如何,非常感谢你:D – Kitinz 2010-09-20 11:31:38