0
목록보기에 맞춤 어댑터를 사용하려고합니다.요소의 순서가 변경되면 Android 사용자 지정 어댑터가 충돌합니다.
모든 행이 코드로 정의됩니다
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/row_image" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/row_title"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/row_description"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/row_period"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:id="@+id/row_edit"
android:layout_marginBottom="5dp"/>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:id="@+id/row_trash"
android:layout_marginTop="5dp"/>
</LinearLayout>
</LinearLayout>
어댑터 클래스 코드 :
public View getView(int position, View convertView, ViewGroup parent){
View v = convertView;
if (v == null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.spec_row, null);
}
Spec i = specs[position];
if (i != null) {
ImageView image = (ImageView) v.findViewById(R.id.row_image);
if (image != null){
String urldisplay = "MY_URL"+i.image;
DownloadImage di=new DownloadImage(urldisplay, image, "baja");
di.execute();
}
TextView title = (TextView) v.findViewById(R.id.row_title);
if (title != null){
title.setText(i.title);
}
TextView description = (TextView) v.findViewById(R.id.row_description);
if (description != null){
description.setText(i.description);
}
TextView period = (TextView) v.findViewById(R.id.row_period);
if (period != null){
period.setText("da "+i.start+" a "+i.finish);
}
ImageView edit = (ImageView) v.findViewById(R.id.row_edit);
edit.setImageResource(R.drawable.edit);
ImageView trash = (ImageView) v.findViewById(R.id.row_trash);
trash.setImageResource(R.drawable.trash);
}
return v;
}
코드는 작품 이상 볼 수 있지만 난 아마도 (마지막 두 이미지를 볼 수 beacause textviews 모든 공간을 사용) 행의 시작 부분에 이미지를 배치하면 (첫 번째 이미지 앞에) 응용 프로그램이 충돌하고 logcat이 다음과 같이 말합니다. Imageview를 Texture로 캐스팅 할 수 없습니다. 어댑터 자바 코드.
왜이 변경 결과가 충돌합니까? 어떻게이 문제를 해결할 수 있습니까?
, 전체 XML을주십시오 .. –
@HamidShatu 업데이트 질문 –
에 한번 청소를 확인하고 프로젝트를 재건하십시오 – Abx