2012-10-24 6 views
0

내 안드로이드 응용 프로그램에 ListAdapter가 있습니다 ... 목록의 각 항목에 ratingBar를 추가하려고합니다. 그 값은 [TAG_RATING ]. 문제는 목록이 표시되고 있으며 ratingBar가 목록의 맨 아래에 붙어 있으며 다소 크다는 것입니다.간단한 어댑터를 사용하여 ListAdapter에 RatingBar 추가하기 올바르게 작동하지 않습니다.

은 참조하십시오 아래의 코드 :

ListAdapter adapter = new SimpleAdapter(
         AllProductsActivity.this, productList, 
         R.layout.list_item, new String[] { TAG_BID, 
           TAG_NAME, 
           TAG_RATING}, 
         new int[] { R.id.pid, R.id.name, R.id.ratingBar}); 
        ((SimpleAdapter) adapter).setViewBinder(new MyBinder()); 
       // updating listview 
       setListAdapter(adapter); 

다음 ViewBinder 클래스는 다음과 같습니다

class MyBinder implements ViewBinder{ 
    public boolean setViewValue(View view, Object data, String textRepresentation) { 
     if(view.getId() == R.id.ratingBar){ 
      String stringval = (String) data; 
      float ratingValue = Float.parseFloat(stringval); 
      RatingBar ratingBar = (RatingBar) view; 
      ratingBar.setRating(ratingValue); 
      return true; 
     } 
     return false; 
    } 
} 

그리고 목록 항목 XML 파일은 다음과 같습니다

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


<TextView 
    android:id="@+id/pid" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:visibility="gone" /> 

<!-- Name Label --> 
<TextView 
    android:id="@+id/name" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:paddingTop="6dip" 
    android:paddingLeft="6dip" 
    android:textSize="17dip" 
    android:textStyle="bold" /> 

    <RatingBar 
    android:id="@+id/rating" 
    style="?android:attr/ratingBarStyleSmall" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:paddingTop="6dip" 
    android:stepSize="0.25" 
    android:numStars="5" 
    /> 

답변

1

RatingBar 위젯은 어댑터에서 사용하는 목록 행 레이아웃에 배치해야합니다 (R.layout.list_item). 지금은위젯을 기본 레이아웃의 ListView 아래에 두었습니다.

+0

방금 ​​몇 분 전에 발견했는데 이미 변경 중입니다 .. – Skindeep2366

+0

딱 그랬지만 내 평가 막대가 큽니다 ... IsIndicator = "True"는 사용하고 있지만 여전히 큰 것입니다. – Skindeep2366

+1

@ Skindeep2366 행 레이아웃 파일을 게시해야합니다. 'isIndicator' 속성을 제거하면'RatingBar'가 더 작아 집니까? – Luksprog

관련 문제