2013-02-18 89 views
1

我目前正在编写一个Android项目,但我在我的xml文件中遇到问题。没有日期选择器,listview运行良好。但是,当我添加日期选择器(不编辑java文件)时,listview消失。以下是我的android xml文件:当添加DatePicker时,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="wrap_content" 
android:background="@drawable/background" 
android:orientation="vertical" > 


<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Enter Date" 
     android:textColor="@android:color/white" 
     android:textSize="25sp" /> 

    <DatePicker 
     android:id="@+id/datePicker1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 

    <Button 
     android:id="@+id/confirm" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Confirm" /> 

</LinearLayout> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:background="@android:color/background_dark" > 

    <ListView 
     android:id="@android:id/list" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:drawSelectorOnTop="false" /> 
</LinearLayout> 

</LinearLayout> 

我的xml文件中是否有错误?

更新: 我发现,在三星GalaxyŸ二重奏甚至出现与日期选择器列表视图,但仍然没有出现在三星Galaxy Note

回答

0

我的猜测是,ListView控件之前的小部件最终以所有的垂直空间和你的列表视图只是没有空间出现。尝试将TextView,Button和DatePicker的高度设置为10dp,然后查看是否可以看到列表。如果可以的话,它的空间问题,你应该考虑使用ScrollView而不是LinearLayout

+0

试过ScrollView但无济于事。我也尝试将DatePicker的高度设置为10dp,但ListView仍然不显示。但是,当我删除Datepicker,甚至增加TextVIew和Button的大小时,ListView出现。 – user1699366 2013-02-18 06:02:16

+0

发现我上面贴出的代码适用于Samsung Galaxy Y,但不适用于Samsung Galaxy Note。这是什么意思? – user1699366 2013-02-18 06:03:53

+0

您的父母'LinearLayout'似乎没有结束标记。这只是一个错误复制..或?另外,你不需要将'ListView'包装在'LinearLayout'中。只需将它作为父'LinearLayout'的子元素,并将其高度设置为“wrap_content”。 – Akash 2013-02-18 06:21:49

0

除了从顶部布局,请删除此行

xmlns:android="http://schemas.android.com/apk/res/android 

0

尝试将重量分配给您的布局,看看。 将android:layout_weight =“1”添加到两个线性布局(不要将此添加到您的主要线性布局)

1

我有一个类似的问题,当我使用DatePicker和ListView与自定义适配器相同的布局,并与我的活动扩展ListActivity和调用getListView()。该列表出现在较旧版本的Android上,但不在较新版本上。我经历过我的适配器的getView()方法没有被调用。

我把它通过改变Android的较新版本的工作:ID =“@机器人:ID /列表”,以自定义的ID,并调用findViewById这个编号,但随后的旧版本有一个“RuntimeException的:你的内容必须有一个ListView,其id属性是'android.R.id.list'“。为了使它在旧版本和新版本上都能工作,我使用了自定义标识和findViewById方法,但是从Activity扩展而不是ListActivity。也许有办法在不避开ListActivity的情况下处理这个问题,但至少对我来说这很有效。