i am new to android. in my application i have a button .i put a onClick listener to it and in onClick function i am looking to take a alert dilago .and looking to inflate a layout on to it.it is xml file from layouts.in that xml i putt a edite text and spinner .after runnig the application i am able to get that layout xml file on to alertdilago .there is no problem with iflating that onto it.
The problem here is as i am trying to enter something onto edittext and try to to press the positive button the application is getting closed.
in onclick i am writing the code as follows
LayoutInflater inflater=LayoutInflater.from(this);
View addView=inflater.inflate(R.layout.view_alert, null);
final EditText input= new EditText(this);
final Spinner inputsp = (Spinner)findViewById(R.id.spalert);
new AlertDialog.Builder(NewGbrainyActivity.this)
.setTitle("ENTER YOUR DETAILS")
.setView(addView)
.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
}
String value = input.getText().toString();
Intent myIntent = new Intent(
"com.pakage.android.newgbrainy.LEVELS");
myIntent.putExtra("name", value);
int requestCode = 1;
startActivityForResult(myIntent,
requestCode);
// finish();
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
// Do nothing.
dialog.dismiss();
}
}).show();
how should i write the code for taking input and pass it to another activity.please help me
Thank you,
maddy.
You are saying “In that xml I putt a edite text and spinner.” if so then you should get the Editext from the xml layout. Instead to create new. Also get spinner view from xml
do this