我在我的ListView中的Checkbox上捕获了适配器构建的单击事件,并构建了我需要在启动ListView的视图中使用的aArrayList
HiddenChannelsListAdapter.java
这是我在getView()
中的customAdapater部分public class HiddenChannelsListAdapter extends BaseAdapter {
public ArrayList<String> slist;
CheckBox checkbox = (CheckBox) convertView.findViewById(R.id.check_channel);
checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
if ( isChecked ) {
if ( !slist.contains(i.get("id")) )
slist.add(i.get("id"));
} else {
for (int j=0;j<slist.size();j++) {
if ( slist.get(j) == i.get("id") ) {
slist.remove(j);
}
}
}
}
});
现在在我的班级ChannelsDialogPreference.java中:
@Override
public void onClick (DialogInterface dialog, int which)
{
super.onClick(dialog, which);
if(which == -1) {
**here I need that slist ArrayList**
}
}
答案 0 :(得分:1)
在你的ChannelsDialogPreference中,将你的slist
arraylist初始化为static,并在HiddenChannelsListAdapter中更改slist的值:
在HiddenChannelsListAdapter中:
CheckBox checkbox = (CheckBox) convertView.findViewById(R.id.check_channel);
checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
if ( isChecked ) {
if ( !slist.contains(i.get("id")) )
ChannelsDialogPreference.slist.add(i.get("id"));
} else {
for (int j=0;j<slist.size();j++) {
if ( slist.get(j) == i.get("id") ) {
ChannelsDialogPreference.slist.remove(j);
}
}
}
}
});
在ChannelsDialogPreference类中:
public static ArrayList<String> slist = new ArrayList<String>();
@Override
public void onClick (DialogInterface dialog, int which)
{
super.onClick(dialog, which);
if(which == -1) {
//Now your can Use your Updated slist here.
}
}
希望它会有所帮助。