2013-02-01 56 views
0

我有像三個複選框下面三個複選框值爲

的Facebook CheckBox1 GOOGLEPLUS CheckBox2 Twitter的CheckBox3

我曾嘗試下面的代碼:

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; 

我宣佈APPUTIL類中的所有這些Static字符串。

當我檢查所有的複選框,或一個或兩個,它給我null,null,null取決於檢查chechk框。

我想複選框的值與選中的複選框。

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); 
     } 
    } 
} 

以上是我現在正在調用該方法,我想選中的值存儲在字符串中,並希望利用它來進行設置text.But我收到facebookfacebookfacebook,意味着重複字符串的是發生。

+0

您確定要創建改變監聽器每次都有一個新的Intent對象? –

+0

,我只是想獲得檢查複選框存儲在字符串中的值在一些文本視圖中使用 – Amrinder

+0

把你的錯誤日誌在這裏 –

回答

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 
       } 
      }}); 

有內置的複選框使用這些U可以方便地通知所有複選框的變化

代碼中的所有三個複選框創建checkedchangelistener .Friend

+0

我試過這個,但再次得到null null null – Amrinder