Android ListView仅显示1项

Android ListView仅显示1项,android,listview,show,Android,Listview,Show,我的布局是这样的:imageview、ratingbar和tabhost包含对用户和信息的审查。对于用户的tabhost review,我正在使用自定义listview,并且我成功地显示了来自用户的所有评论。但我的问题是,你们可以看到下面的图片listview高度是只为1个项目包装内容,若我滚动它,它可以加载所有数据 这是一个布局,我想让它显示多个项目作为家长的高度 这里是我的布局xml <RelativeLayout xmlns:android="http://schemas.andr

我的布局是这样的:imageview、ratingbar和tabhost包含对用户和信息的审查。对于用户的tabhost review,我正在使用自定义listview,并且我成功地显示了来自用户的所有评论。但我的问题是,你们可以看到下面的图片listview高度是只为1个项目包装内容,若我滚动它,它可以加载所有数据

这是一个布局,我想让它显示多个项目作为家长的高度

这里是我的布局xml

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

    <!-- HEADER -->
    <LinearLayout
        android:id="@+id/header"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" 
        android:layout_centerHorizontal="true"
        android:background="#dcdcdc"
       android:paddingTop="5dp"
       android:paddingBottom="5dp"
        android:layout_alignParentTop="true">
        <ImageView 
            android:id="@+id/ivplacedetail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:src="@drawable/search"/>
        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Name" />   
        <RatingBar
            android:id="@+id/ratingBar1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />     

    </LinearLayout>
    <!-- FOOTER -->
    <LinearLayout
        android:id="@+id/footer"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" 
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        android:background="#a9d633">
        <Button 
           android:id="@+id/btnhome"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:layout_weight="1"
           android:layout_marginLeft="2dp"
           android:layout_marginRight="2dp"
           android:layout_marginTop="2dp"
           android:layout_marginBottom="2dp"
           android:text="Home"
           android:background="@layout/round_border"/>          
        <Button 
           android:id="@+id/btnbookmark"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:layout_weight="1"
           android:layout_marginLeft="2dp"
           android:layout_marginRight="2dp"
           android:layout_marginTop="2dp"
           android:layout_marginBottom="2dp"
           android:text="Bookmark"
           android:background="@layout/round_border"/>  
        <Button 
           android:id="@+id/btnnearby"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:layout_weight="1"
           android:layout_marginLeft="2dp"
           android:layout_marginRight="2dp"
           android:layout_marginTop="2dp"
           android:layout_marginBottom="2dp"
           android:text="Nearby"
           android:background="@layout/round_border"/>             
    </LinearLayout>     
    <ScrollView 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/footer"
        android:layout_below="@+id/header">     
        <TabHost
            android:id="@android:id/tabhost"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">

                <TabWidget
                    android:id="@android:id/tabs"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" />

                <FrameLayout
                    android:id="@android:id/tabcontent"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"/>

            </LinearLayout> 
        </TabHost>                          
    </ScrollView>
</RelativeLayout>
我的listview自定义布局在这里

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

     <ImageView 
         android:id="@+id/imguser" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content"
         android:layout_margin="1dp"
         android:src="@drawable/atmicon"
         android:scaleType="fitCenter"> 
     </ImageView>

    <TextView 
        android:id="@+id/lbluser" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"  
        android:layout_marginLeft="5dp"
        android:layout_marginTop="3dp"
        android:layout_marginBottom="1dp"
        android:layout_toRightOf="@+id/imguser"
        android:textColor="#4068ec"
        android:text="Nama User"> 
    </TextView> 
    <TextView 
        android:id="@+id/lblwaktu" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"  
        android:layout_toRightOf="@+id/imguser"
        android:layout_below="@+id/lbluser"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="1dp"
        android:layout_marginBottom="1dp"
        android:text="Waktu Review">
    </TextView> 
    <TextView 
        android:id="@+id/lblreview" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_toRightOf="@+id/imguser"
        android:layout_below="@+id/lblwaktu"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="1dp"
        android:layout_marginBottom="1dp"
        android:text="isi Review">        
    </TextView>  
</RelativeLayout>
我的列表视图布局

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

    <ListView
        android:id="@+id/lvreview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</LinearLayout>

有人能帮我修改布局吗?

首先在主类中声明适配器

private ListViewReviewAdapter reviewAdapter;
第二,首先初始化适配器,然后向其中添加数据,即使arruserreview为空

reviewAdapter = new ListViewReviewAdapter(getBaseContext(), arruserreview);
lvreview.setAdapter(reviewAdapter);
在for循环中,执行以下操作:

for (int i=1;i<=10;i++) {
    UserReviewClass userreview=new UserReviewClass(String.valueOf(i),"Budi"+String.valueOf(i),"10/19/2014","Tempatnya lumayan. Pelayanan yang diberikan baik");
    arruserreview.add(userreview);
    reviewAdapter.notifyDataSetChanged();
}
所以你会有这样的东西:

ArrayList<UserReviewClass> arruserreview = new ArrayList<UserReviewClass>();
ListView lvreview ;
private ListViewReviewAdapter reviewAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_place_review);

    lvreview     = (ListView) findViewById(R.id.lvreview);
    reviewAdapter = new ListViewReviewAdapter(getBaseContext(), arruserreview);
    lvreview.setAdapter(reviewAdapter);

    for (int i=1;i<=10;i++) {
        UserReviewClass userreview=new UserReviewClass(String.valueOf(i),"Budi"+String.valueOf(i),"10/19/2014","Tempatnya lumayan. Pelayanan yang diberikan baik");
        arruserreview.add(userreview);
        reviewAdapter.notifyDataSetChanged();
    }


}

正如Daniel M提到的,声明您的适配器这只是一个良好的实践,原因有很多

private ListViewReviewAdapter reviewAdapter;
在for循环中构造arruserreview阵列后,将该阵列传递给适配器并进行设置:

reviewAdapter = new ListViewReviewAdapter(this, arruserreview);
lvreview.setAdapter(reviewAdapter);
在阵列适配器中,将构造函数更改为:

public ListViewReviewAdapter(Context context, ArrayList<UserReviewClass> results) {
    DataProcessorResult = results;
    mycontext = context;
    myInflater = LayoutInflater.from(context);
}

当您在适配器中登录时,您得到的值是10或1..问题可能是在循环完成之前填充适配器所有datareview都已显示,但现在的问题是它的高度仅适用于1 datareview,因为链接显示在阵列已知之前初始化和设置阵列适配器是不必要的,在执行for循环时,NOTIFYDATASETCHANGE都没有更改。
final Context mycontext=parent.getContext();