2011-04-26 7 views
1

안녕하세요, 친구, 저는 ToDoTask 응용 프로그램을 Android에서 만듭니다. 나는 "ListView"에서 모든 작업을 표시합니다. 이제 listview의 각 작업 앞에 이미지를 추가하고 싶습니다. 이것은 작업의 "완료"또는 "실행 취소"상태를 보여주는 작은 이미지입니다.ListView의 이미지

어떻게해야합니까? 모든 작업 목록을 데이터베이스에 저장했습니다. .....

+0

확인이 link 희망이 당신의 문제를 해결합니다 –

답변

0

ListView에 작업을 표시하려면 ListView # getView()를 덮어 써야합니다. 이제 예를 들어 TextView를 반환하지만, 이것을 변경하고 ImageView가 포함 된 LinearLayout을 반환하고 TextView를 반환 할 수 있습니다.

0

사용자 지정 목록 어댑터를 만들고 getView() 함수를 재정의해야합니다. 그런 다음 텍스트 뷰와 이미지 뷰가 포함 된 사용자 정의 목록 뷰 항목의 레이아웃을 만듭니다. 그런 다음 사용자 정의 목록 어댑터의 getView() 함수에서 textview 및 imageview를 초기화하고 텍스트 뷰 및 이미지 뷰의 이미지 값을 원하는대로 변경할 수 있습니다.

의 getView() 함수 :

public View getView(int position, View convertView, ViewGroup viewGroup) 
{ 
    TextView tv = (TextView)convertView.findViewById(R.id.tvChild); 
    tv.setText("example text"); 
    ImageView image = (ImageView)convertView.findViewById(R.id.image); 
    // You can choose to use either of the below functions to set the image 
    image.setImageBitmap(null); 
    image.setImageDrawable(null); 
    image.setImageResource(Position); 
} 

사용자 정의 목록보기 항목 레이아웃 :

<LinearLayout android:id="@+id/LinearLayout01" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="horizontal"> 
     <ImageView android:id="@+id/image" 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content" 
       android:gravity="center_vertical"> 
     </ImageView> 
     <TextView android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:gravity="center_vertical" 
       android:id="@+id/tvChild" 
       android:layout_marginLeft="6dip" 
</LinearLayout>