我有一个ExpandableListView并在每个 Parent Row 内。
我有一个切换按钮,当我打开一个切换按钮时,在下面滚动时,我打开了多个切换按钮。为什么会发生这种情况,我在日志中正确获取了 groupPosition 的所有内容?
这是我的代码:
public class WifiAPListAdapter extends BaseExpandableListAdapter {
private WifiAPListActivity context;
public ArrayList<ExpandListGroup> groups;
private WifiManager wifiManager;
WifiStatus checkWifiStatus;
public ToggleButton togglebtn;
int pos;
Holder holder;
int previousPosition = -1;
private static final int CHILD_COUNT = 1;
public WifiAPListAdapter(WifiAPListActivity context,
ArrayList<ExpandListGroup> result) {
this.context = context;
this.groups = result;
wifiManager = (WifiManager) context
.getSystemService(Context.WIFI_SERVICE);
checkWifiStatus = new WifiStatus(context);
}
public Object getChild(int groupPosition, int childPosition) {
return groups.get(groupPosition);
}
public long getChildId(int groupPosition, int childPosition) {
return groupPosition;
}
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View view, ViewGroup parent) {
previousPosition = groupPosition;
ExpandListGroup child = (ExpandListGroup) getChild(groupPosition,
groupPosition);
// Log.i("", "getChildView: "+childPosition);
if (view == null) {
holder = new Holder();
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = infalInflater.inflate(R.layout.list_child_item, null);
holder.label_ssid = (TextView) view.findViewById(R.id.label_ssid);
holder.tv_ssid = (TextView) view.findViewById(R.id.tvssid);
holder.label_bssid = (TextView) view.findViewById(R.id.label_bssid);
holder.tv_bssid = (TextView) view.findViewById(R.id.tvbssid);
holder.label_capabilities = (TextView) view
.findViewById(R.id.label_capabilities);
holder.tv_capabilities = (TextView) view
.findViewById(R.id.tvcapabilities);
holder.label_signalStrength = (TextView) view
.findViewById(R.id.label_signalstrength);
holder.tv_signalStrength = (TextView) view
.findViewById(R.id.tvsignalstrength);
holder.wifi_signalimg = (ImageView) view.findViewById(R.id.signal);
view.setTag(holder);
} else {
holder = (Holder) view.getTag();
}
// *********************setting data to the child list**************
holder.tv_ssid.setText(child.getSSID());
holder.tv_bssid.setText(child.getBSSID());
holder.tv_capabilities.setText(child.getCapabilities());
holder.tv_signalStrength.setText(child.getData());
Bitmap bitmap = setSignalImage(Integer.parseInt(child.getData()));
holder.wifi_signalimg.setImageBitmap(bitmap);
return view;
}
public int getChildrenCount(int groupPosition) {
Log.i("", "getChildrenCount: " + groupPosition);
return CHILD_COUNT;
}
public Object getGroup(int groupPosition) {
return groups.get(groupPosition);
}
public int getGroupCount() {
Log.i("", "getGroupCount: " + groups.size());
return groups.size();
}
public long getGroupId(int groupPosition) {
return groupPosition;
}
public View getGroupView(int groupPosition, boolean isLastChild, View view,
ViewGroup parent) {
Log.i("", "getGroupView: " + groupPosition);
if (view == null) {
holder = new Holder();
LayoutInflater inf = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inf.inflate(R.layout.list_parent_items, null);
holder.tv_ssid = (TextView) view.findViewById(R.id.ssid);
holder.tv_bssid = (TextView) view.findViewById(R.id.bssid);
holder.btn_toggle = (ToggleButton) view.findViewById(R.id.togBtn);
// holder.btn_toggle.setTag(groups.get(groupPosition).getBSSID());
view.setTag(holder);
} else {
holder = (Holder) view.getTag();
}
// holder.btn_toggle.setTag(groups.get(groupPosition).getBSSID());
holder.tv_ssid.setText(groups.get(groupPosition).getSSID());
holder.tv_bssid.setText(groups.get(groupPosition).getBSSID());
return view;
}
public void toggle(View v) {
if (holder.btn_toggle.isChecked()) {
}
Log.i("", "toggle");
}
public boolean hasStableIds() {
return true;
}
public boolean isChildSelectable(int arg0, int arg1) {
return true;
}
任何人都可以在不移除支架的情况下告诉一个避免这个问题的好方法,因为如果我有 n 个项目,那么每次我们应该使用支架时都绘制视图不是一个好主意。