blob: 050c5c6eb0c513d6eebb259aab2a3370f24cee66 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
package net.miz_hi.smileessence.dialog;
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface.OnClickListener;
import android.view.LayoutInflater;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ScrollView;
public class CheckBoxListDialog
{
private Activity activity;
private String title;
private OnClickListener onClicked;
private CheckBoxItem[] items;
public CheckBoxListDialog(Activity activity)
{
this.activity = activity;
}
public void setTitle(String str)
{
this.title = str;
}
public void setOnClicked(OnClickListener listener)
{
this.onClicked = listener;
}
public CheckBoxItem[] getItems()
{
return items;
}
public void setItems(CheckBoxItem... items)
{
this.items = items;
}
public Dialog createDialog()
{
LayoutInflater inflater = activity.getLayoutInflater();
ScrollView scroll = new ScrollView(activity);
LinearLayout linearLayout = new LinearLayout(activity);
linearLayout.setOrientation(LinearLayout.VERTICAL);
LayoutParams p = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
p.setMargins(0, 10, 0, 10);
for (final CheckBoxItem item : items)
{
CheckBox checkbox = new CheckBox(activity);
checkbox.setLayoutParams(p);
checkbox.setText(item.name);
checkbox.setChecked(item.value);
checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
item.value = isChecked;
}
});
linearLayout.addView(checkbox);
}
scroll.addView(linearLayout);
ContentDialog dialog = new ContentDialog(activity, title);
dialog.setContentView(scroll);
dialog.setOnClickListener(onClicked);
return dialog.create();
}
public static class CheckBoxItem
{
public String name;
public boolean value;
public CheckBoxItem(String name, boolean startValue)
{
this.name = name;
this.value = startValue;
}
}
}
|