大佬教程收集整理的这篇文章主要介绍了android中的自定义复选框难度,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
class imagecheckBoxAdapter extends ArrayAdapter<String> implements VIEw.onClickListener
{
private final Context context;
private final ArrayList<String> values;
private final Map< String, Smbfile> obj;
private 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;
for (int i = 0; i < values.size(); i++) {
checks.add(i, falsE);
}
}
@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);
checkBox chk = (checkBoX) rowVIEw.findVIEwByID(R.ID.checkBox1);
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();
}
chk.setTag(Integer.valueOf(position));
// Set a Listener for the checkBox
chk.setonClickListener(this);
//Sets the state of CB, since we have the List of checked CB
chk.setchecked(checks.get(position));
return rowVIEw;
}
@OverrIDe
public voID onClick(View view) {
Integer index = (Integer)vIEw.getTag();
Boolean state = checks.get(index.intValue());
checks.set(index.intValue(), !statE);
}
}
如何修改此imagecheckBoxAdapter代码以在滚动时保持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="@R_673_10107@://scheR_402_11845@as.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>
以上是大佬教程为你收集整理的android中的自定义复选框难度全部内容,希望文章能够帮你解决android中的自定义复选框难度所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。