我已经尝试过:
EditText edText1 = (EditText) findViewById(R.id.editText1);
String str = edText1.getText().toString();
我只获得数字而不是字符。 如何获取EditText文本以便将其放在字符串上并对其进行操作?
答案 0 :(得分:1)
// first set the Input type of the EditText in the Java class like this;
EditText edText1 = (EditText) findViewById(R.id.editText1);
edText1.setInputType(InputType.TYPE_CLASS_TEXT);
String str = edText1.getText().toString();
答案 1 :(得分:0)
这就是我项目中按钮的外观
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
createLog("Called method onCreate");
Button addTextButton = (Button) findViewById(R.id.button);
final EditText vEditText = (EditText) findViewById(R.id.editText);
addTextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String enteredText = vEditText.getText().toString();
if (enteredText.length() > 0){
String existingText =((TextView) findViewById(R.id.textView)).getText().toString();
((TextView) findViewById(R.id.textView)).setText(existingText + (char)10 + (char)13 + enteredText );
vEditText.setText("");
}
}
});
答案 2 :(得分:0)
创建获取方法
editText = findViewById(R.id.editText);
String s = getString(editText.getText().toString()
public String getString(String text){
return text;
}