2014-10-18 66 views
0

我有这个序列的布局:imageview,ratingbar和tabhost(包含用户和信息的审查)。对于用户的tabhost评论,我使用自定义的listview,并且我成功地显示了用户的所有评论。但我的问题,你可以看到下面的图片(列表视图身高只有1项包裹的内容,如果我把它的滚动,它可以加载所有数据)ListView只显示1项

http://pbrd.co/1wctFFz

而且我想使这个布局(它显示多个项目,作为父母的身高)

http://pbrd.co/1wctBFZ

这里我的布局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> 

我LIS tview自定义布局在这里

<?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> 

我的ListView布局

<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> 

有人可以帮我解决我的布局?

+0

当您将其登录到适配器中时,您会得到10或1个什么值?问题可能是该适配器在循环完成之前填充 – Elltz 2014-10-18 18:04:39

+0

已显示所有数据(查看),但问题现在它的高度仅仅是1个数据(查看),链接显示 – Kaizternn 2014-10-18 19:11:20

回答

0

首先声明你的适配器在主类

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(); 
    } 


} 
+0

在数组已知之前初始化和设置阵列适配器不是必需的,在执行for-loop时,也不需要notifyDataSetChanged()。 – mjp66 2014-10-18 18:13:51

0

正如丹尼尔M提到的那样,声明你的适配器(这只是各种原因的好习惯)。

private ListViewReviewAdapter reviewAdapter; 

一旦arruserreview阵列中的for循环,数组传递到您的适配器,并设置它构造:

reviewAdapter = new ListViewReviewAdapter(this, arruserreview); 
lvreview.setAdapter(reviewAdapter); 

在你的阵列适配器,改变你的构造函数:

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

由于您在reviewAdapter和构造函数中将上下文作为参数传递,因此可以从适配器类中删除以下行:

final Context mycontext=parent.getContext();