이 이미지를 수정하는 방법 CheckBoxAdapter 코드는 스크롤 할 때 checkBox의 상태를 유지하기 위해 (즉, 체크 된 모든 체크 박스는 스크롤 한 후에도 체크되어야한다.) 또한 체크 된 변수는 배열에 저장되어야한다.)?안드로이드의 사용자 정의 체크 상자 난이도
class imageCheckBoxAdapter extends ArrayAdapter<String>
{
private final Context context;
private final ArrayList<String> values;
private final Map< String, SmbFile> obj;
static ArrayList<Boolean> checks=new ArrayList<Boolean>();
public imageCheckBoxAdapter(Context context,ArrayList<String> values,Map< String, SmbFile>obj)
{
super(context, R.layout.row_checkbox, values);
this.context = context;
this.values = values;
this.obj=obj;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.row_checkbox, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.text1_check);
textView.setText(values.get(position));
ImageView imageView = (ImageView) rowView.findViewById(R.id.icon_image_check);
try
{
if((obj.get(values.get(position)).isFile()))
{
imageView.setImageResource(R.drawable.view_file_icon);
}
else
{
imageView.setImageResource(R.drawable.view_folder_icon);
}
}
catch (SmbException e)
{
Toast.makeText(context,"Network error",Toast.LENGTH_SHORT).show();
Log.d("id1", "error1");
e.printStackTrace();
}
return rowView;
}
}
row_checkbox.xml는
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false" />
<ImageView
android:id="@+id/icon_image_check"
android:layout_width="50px"
android:layout_height="50px"
android:layout_marginLeft="5px"
android:layout_marginRight="20px"
android:layout_marginTop="5px"
android:src="@drawable/view_file_icon" >
</ImageView>
<TextView
android:id="@+id/text1_check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@+id/label"
android:textSize="30px"
android:typeface="sans">
</TextView>
</LinearLayout>
안녕하세요,이 코드에서 '상태'변수의 사용은 뭐죠? @Override 공개 무효 onClick (보기보기) { 정수 인덱스 = (정수) view.getTag(); 부울 상태 = checks.get (index.intValue()); checks.set (index.intValue(), true); } – raghs
외부에서 '수표'정적 변수를 읽으려고하면 오류가 발생합니다 .. 왜? – raghs
수표에 액세스하지 않으면 수표 값 목록에 대한 getter 메서드가 있고 위 코드를 편집합니다. – Joey