I am having a problem in storing a Edit able Text value in a string. I just want to store a value that user enter store it in some variable. i used toast just after storing a value to check whether the value is store in it or not and toast doesn’t show any value. i try the following code but didnt find it helpful.
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);
}
});
}
}
Try:
Toasts do not show unless the
show()method is called. themakeText()method returns a Toast object which you must use to display the toast.You normally get a lint warning about this, but you seem to have suppressed it with
@SuppressLint("ShowToast").