我有一个带有 [PICTURE] - [TEXT] - [CHECKBOX] 的自定义列表视图当我选择一个复选框并且我喜欢向下滚动时,会选择更多复选框。为什么呢?我该如何解决这个问题?
-> 我只选择一个复选框 -> 然后我向下滑动并选择了更多复选框
最好的问候 MSeiz5
我的自定义适配器_
public class CustomAdapter extends BaseAdapter{
TextView rawTextView;
boolean[] checkBoxState;
LayoutInflater mInflater;
ListContent holder;
private ArrayList<Notification> arrNotification=null;
private ArrayList<HashMap<String, String>> arrlist = new ArrayList<HashMap<String, String>>();
public CustomAdapter(ArrayList<HashMap<String, String>> arrlist) {
arrNotification = new ArrayList<Notification>();
mInflater = LayoutInflater.from(connected_upload.this);
checkBoxState=new boolean[arrNotification.size()];
this.arrlist = arrlist;
}
@Override
public int getCount() {
return arrlist.size();
}
public int getCount2()
{
return arrNotification.size();
}
public Object getItem2(int position)
{
return position;
}
public long getItemId2(int position)
{
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = mInflater.inflate(R.layout.connected_upload, null);
holder=new ListContent();
holder.checkbox = (CheckBox) convertView.findViewById( R.id.checkBox1 );
convertView.setTag(holder);
if(convertView == null){
// LayoutInflater class is used to instantiate layout XML file into its corresponding View objects.
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.connected_upload_row, null);
holder=new ListContent();
holder.checkbox = (CheckBox) convertView.findViewById( R.id.checkBox1 );
convertView.setTag(holder);
}
// R.id.img_list, R.id.string_cell
maptemp=new HashMap<String, String>();
maptemp=arrlist.get(position);
rawTextView = (TextView) convertView.findViewById(R.id.string_cell);
rawTextView.setText(maptemp.get("string_cell"));
if (isfolder == true){
imgview=(ImageView) convertView.findViewById(R.id.img_list);
imgview.setImageResource(R.drawable.folder);
} else {
Bitmap test = getbitpam(maptemp.get("img_list"));
imgview=(ImageView) convertView.findViewById(R.id.img_list);
imgview.setImageBitmap(test);
System.gc();
}
return convertView;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
}
日志猫:
01-16 13:41:05.885: E/AndroidRuntime(1720): FATAL EXCEPTION: main
01-16 13:41:05.885: E/AndroidRuntime(1720): java.lang.NullPointerException
01-16 13:41:05.885: E/AndroidRuntime(1720): at mseiz.freeftp.connected_upload$CustomAdapter.getView(connected_upload.java:306)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.AbsListView.obtainView(AbsListView.java:2465)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.ListView.measureHeightOfChildren(ListView.java:1250)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.ListView.onMeasure(ListView.java:1162)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.view.View.measure(View.java:15481)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.view.View.measure(View.java:15481)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5057)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.view.View.measure(View.java:15481)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5057)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1396)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.view.View.measure(View.java:15481)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5057)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
01-16 13:41:05.885: E/AndroidRuntime(1720): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2361)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.view.View.measure(View.java:15481)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5057)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.view.View.measure(View.java:15481)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5057)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1396)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.view.View.measure(View.java:15481)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5057)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.view.View.measure(View.java:15481)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5057)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1396)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.view.View.measure(View.java:15481)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5057)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.view.View.measure(View.java:15481)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.view.View.measure(View.java:15481)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5057)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.view.View.measure(View.java:15481)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.LinearLayout.measureVertical(LinearLayout.java:833)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.view.View.measure(View.java:15481)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5057)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1396)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1038)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.LinearLayout.onMeasure(LinearLayout.java:576)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.view.View.measure(View.java:15481)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5057)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1396)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.view.View.measure(View.java:15481)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5057)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.view.View.measure(View.java:15481)
01-16 13:41:05.885: E/AndroidRuntime(1720): at android.view.ViewGroup.measureChildWithMargins(V