2012-06-30 33 views
-4

我想在一個字符串值,請執行下列操作:當複選框中檢驗TextView的出現,則用戶可以把他所需要的,但問題是我不能讓在EditText中寫入的文字將其放入字符串變量中,因爲它在初始值爲「無」時會進入if語句。任何幫助?得到的EditText if語句

我新在這個網站,這裏是代碼的我說的

SendSMS.setOnCheckedChangeListener(new OnCheckedChangeListener() { 
     public void onCheckedChanged(CompoundButton buttonView, 
       boolean isChecked) { 
      if (isChecked == true) { 
       sendText.setVisibility(0); 
       smstext = sendText.getText().toString(); 
      } else if (isChecked == false) { 
       sendText.setVisibility(8); 
       smstext = ""; 
      } 

     } 
    }); 

這裏的部分..檢查sendsms到真正的EditText(sendText)將出現

後。 。 。 。 。 。

這裏,當用戶輸入任何文字,我需要把它轉換成字符串(SMS)存儲在數據庫等,爲失誤遺憾

break; 
    case R.id.SaveImage: 
     String x = EventName.getText().toString(); 
     if (x.contentEquals("")) { 
      Toast.makeText(getApplicationContext(), "Enter a Title", 
        Toast.LENGTH_SHORT).show(); 
     } else { 

      Intent i = new Intent(getApplicationContext(), Swipe.class); 
      startActivity(i); 
      Toast.makeText(getApplicationContext(), "Event saved", 
        Toast.LENGTH_SHORT).show(); 
      String typename = type; 
      String name = EventName.getText().toString(); 
      String location = EventLocation.getText().toString(); 
      String dateFrom = DateFrom.getText().toString(); 
      String dateTo = EbDate.getText().toString(); 
      String timeFrom = mPickTime.getText().toString(); 
      String timeTo = EbTime.getText().toString(); 
      String duration = durationresult.getText().toString(); 
      String alarm = alarmresult.getText().toString(); 
      String repeat = repeatresult.getText().toString(); 
      String audios = Audios; 
      String sms = smstext; 
      String call = calltext; 
      mySQLiteAdapter.insert(name, location, dateFrom, dateTo, 
        timeFrom, timeTo, duration, alarm, repeat, typename, 
        audios, sms, call); 

      updateList(); 
      // reset form 
      EventName.setText(null); 
      EventLocation.setText(null); 

      break; 
     } 
    } 
} 
+1

你嘗試過什麼?請發佈一些代碼,以幫助其他人喜歡幫助你 –

+0

代碼需要.. –

+0

如果你不發佈代碼,我們只能回覆一個算法,這將不會幫你很多.. –

回答

0

看來,只有時間你設置smstext是當複選框的值發生變化時。用戶只能在該文本框可見時輸入文本,所以當複選框的值發生變化時,邏輯上文本框爲空,並且smstext將始終爲空。

你有沒有嘗試過這樣的事情:

case R.id.SaveImage: 
     ... 
     String sms = sendText.getText().toString(); 
     ... 
+0

哦,對,解決方案很容易! 謝謝。 – hhyari