我在将可编辑文本值存储在字符串中时遇到问题。我只想存储用户输入的值,将其存储在某个变量中。我在存储一个值后使用 toast 来检查该值是否存储在其中,并且 toast 没有显示任何值。我尝试以下代码,但没有发现它有帮助。
package com.example.electropollsys;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class CreateAcc extends Activity {
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.create_acc);
final Button b = (Button) findViewById(R.id.button3);
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(CreateAcc.this, SignIn.class);
i.addFlags(
Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
}
});
final Button a = (Button) findViewById(R.id.button1);
a.setOnClickListener(new View.OnClickListener() {
@SuppressLint("ShowToast")
public void onClick(View v){
EditText input1= (EditText)findViewById(R.id.fname1);
String fname = input1.getEditableText().toString();
EditText input2= (EditText) findViewById(R.id.lname1);
String lname = input2.getEditableText().toString();
Toast.makeText(CreateAcc.this,"...."+fname+"...." , Toast.LENGTH_LONG);
Toast.makeText(CreateAcc.this,"...."+lname+"...." , Toast.LENGTH_LONG);
}
});
}
}