I have three check box like below
我有三个复选框,如下所示
Facebook CheckBox1 GooglePlus CheckBox2 Twitter CheckBox3
Facebook CheckBox1 GooglePlus CheckBox2 Twitter CheckBox3
I had tried the below code :
我试过以下代码:
if (facebookChackbox.isChecked())
{
facebook_checkbox = true;
AppUtil.facebookNetworkList_EditPost ="Facebook";
list.add("facebook");
Intent i = new Intent();
i.putExtra("facebook_boolean", true);
Log.e("facebook checkbox", "facebook checkbox" + facebook_checkbox);
}
else
{
AppUtil.facebookNetworkList_EditPost ="";
}
if (twitterChackbox.isChecked())
{
twitter_checkbox = true;
AppUtil.twitterNetworkList_EditPost ="Twitter";
list.add("twitter");
Intent i = new Intent();
i.putExtra("twitter_boolean", true);
Log.e("twitter checkbox", "twitter checkbox" + twitter_checkbox);
}
else
{
AppUtil.twitterNetworkList_EditPost ="";
}
if (googleChackbox.isChecked())
{
AppUtil.gpNetworkList_EditPost ="Google Plus";
googleplus_checkbox = true;
list.add("gplus");
Intent i = new Intent();
i.putExtra("google_plus_boolean", true);
Log.e("google plus checkbox", "google plus checkbox" + googleplus_checkbox);
}
else
{
AppUtil.gpNetworkList_EditPost ="";
}
AppUtil.SocialNetworkingList_EditPost = AppUtil.facebookNetworkList_EditPost+""+AppUtil.twitterNetworkList_EditPost+""+AppUtil.gpNetworkList_EditPost;
I have declared all these Static string in APPUTIL class .
我在APPUTIL类中声明了所有这些静态字符串。
When i had check all the check box ,or one or two ,it is giving me null,null,null depends on checking the chechk box.
当我检查所有复选框,或一两个,它给我null,null,null取决于检查chechk框。
I want the value of checkbox with checkedbox which is selected.
我想要选中复选框的复选框值。
private void processCheckboxes() {
// TODO Auto-generated method stub
list = new ArrayList<String>();
sb = new StringBuilder();
if (facebookChackbox.isChecked())
{
facebook_checkbox = true;
AppUtil.facebookNetworkList_EditPost ="Facebook";
list.add("facebook");
Intent i = new Intent();
i.putExtra("facebook_boolean", true);
Log.e("facebook checkbox", "facebook checkbox" + facebook_checkbox);
}
else
{
AppUtil.facebookNetworkList_EditPost ="";
}
if (twitterChackbox.isChecked())
{
twitter_checkbox = true;
AppUtil.twitterNetworkList_EditPost ="Twitter";
list.add("twitter");
Intent i = new Intent();
i.putExtra("twitter_boolean", true);
Log.e("twitter checkbox", "twitter checkbox" + twitter_checkbox);
}
else
{
AppUtil.twitterNetworkList_EditPost ="";
}
if (googleChackbox.isChecked())
{
AppUtil.gpNetworkList_EditPost ="Google Plus";
googleplus_checkbox = true;
list.add("gplus");
Intent i = new Intent();
i.putExtra("google_plus_boolean", true);
Log.e("google plus checkbox", "google plus checkbox" + googleplus_checkbox);
}
else
{
AppUtil.gpNetworkList_EditPost ="";
}
AppUtil.SocialNetworkingList_EditPost = AppUtil.facebookNetworkList_EditPost+""+AppUtil.twitterNetworkList_EditPost+""+AppUtil.gpNetworkList_EditPost;
for (int zz = 0; zz < list.size(); zz++) {
network = list.get(zz);
if (zz < list.size() - 1)
{
Log.i("list.size()",""+list.size());
Log.i("list.size() - 1",""+list.size());
Log.i("network",""+network);
sb.append(network + "," + network + "," + network);
Log.i("sb",""+sb);
}
else
{
Log.e("log", "List----" + zz + network);
network_list = network;
network_list = network + "," + network + "," + network;
// network_list=network+""+network+"&gplus="+network+"&twitter"+
// "" +network;
sb.append(network + "," + network + "," + network);
}
}
}
Above is the method which i am calling now ,i want to store the checked value in the string and want to use that for setting the text.But i am getting the facebookfacebookfacebook,means repeating of the string is happening.
以上是我现在调用的方法,我想将检查的值存储在字符串中,并希望使用它来设置文本。但是我得到了facebookfacebookfacebook,意味着重复字符串正在发生。
1 个解决方案
#1
0
yourcheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
if (isChecked) {
//do something when checkbox is checked
}
else {
//do something when checkbox is unchecked
}
}});
there is built in checkbox changed listener using these u can easily notify the changes for all checkboxes
内置复选框已更改的侦听器使用这些可以轻松通知所有复选框的更改
Create checkedchangelistener for all three checkboxes in your code .Friend
为代码中的所有三个复选框创建checkedchangelistener。友好
#1
0
yourcheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
if (isChecked) {
//do something when checkbox is checked
}
else {
//do something when checkbox is unchecked
}
}});
there is built in checkbox changed listener using these u can easily notify the changes for all checkboxes
内置复选框已更改的侦听器使用这些可以轻松通知所有复选框的更改
Create checkedchangelistener for all three checkboxes in your code .Friend
为代码中的所有三个复选框创建checkedchangelistener。友好