ExpandableListViewがあり、各 Parent Row 内にあります。
私はトグルボタンを持っています.1つのトグルボタンをオンにすると、下にスクロールすると複数のトグルボタンがオンになります。なぜこれが起こっているのですか? ログに 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個のアイテムがある場合、ホルダーを使用するたびにビューを描画するのは良い考えではありません.