2014-10-18 5 views
0

나는이 순서로 레이아웃이 있습니다 : imageview, ratingbar 및 tabhost (사용자 및 정보 검토 포함). 사용자의 탭 호스트 검토를 위해 사용자 정의 listview를 사용하고 있으며 사용자의 모든 리뷰를 성공적으로 표시했습니다. 하지만 내 문제는, 당신은 (ListView 만 표시 1 항목

http://pbrd.co/1wctFFz

내가 만들고 싶어이 하나 개의 레이아웃 (목록보기 높이 내가 그것을 이동하면, 모든 데이터를로드 할 수 있습니다, 단 1 개 항목에 대한 내용을 포장입니다) 이미지 아래에 볼 수 있습니다 그것은 내 레이아웃 XML 여기

http://pbrd.co/1wctBFZ

)

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

내 문양을 부모의 높이와 같은 여러 항목을 표시 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> 

내 목록보기 레이아웃은

<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

+0

모든 데이터 (검토)가 이미 표시되어 있지만 문제가 있습니다. 이제 높이가 1 데이터 (리뷰)에 대한 것입니다. – Kaizternn

답변

0

먼저 arruserreview이 당신의 루프에서

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

비어있는 경우에도, 메인 클래스의 어댑터가 다음에 데이터를 추가 모든 처음 초기화의

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

이렇게하면됩니다.

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 루프를 실행하는 동안 notifyDataSetChanged()도 아닙니다. – mjp66

0

Daniel M이 언급했듯이 어댑터를 선언하십시오 (여러 가지 이유로 좋은 습관입니다). 어레이 어댑터

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

을로 생성자를 변경 :

public ListViewReviewAdapter(Context context, ArrayList<UserReviewClass> results) { 
    DataProcessorResult = results; 
    mycontext = context; 
    myInflater = LayoutInflater.from(context); 
} 
arruserreview 어레이가 루프, 어댑터에 어레이를 통과하고 설정하여 구성된되면

private ListViewReviewAdapter reviewAdapter; 

reviewAdapter 및 생성자의 매개 변수로 컨텍스트를 전달하기 때문에 어댑터 클래스에서 다음 줄을 제거 할 수 있습니다.

final Context mycontext=parent.getContext(); 
관련 문제