I need to display the selection that I have chosen from spinner and checkbox from one activity to another activity,however I have completed for editText.I have also set the spinner and values for the spinner in arraylist, i have no idea of how to proceed further for spinner and also I don't know how to use checkbox.I need to pass the spinner and checkbox selected values from MainActivity to secondActivity and I need to display the results as a simple textview in secondActivity as follows:
I need to get my final results something like this:
Name: Da1
Email: xxxxxxx@gmail.com
Number: 0123456789
Degree: BE or ME(whatever I am choosing)
Place: Australia
Please help me friends. Many thanks in advance. Herewith I have enclosed my codings. Thanks.
MainActivity.java:
public class MainActivity extends Activity implements
AdapterView . OnItemSelectedListener {
EditText Name,Email,Number;
Button submit;
String [] countryNames ={ "India" ,"Australia" ,"Pakistan" ,"Afghanistan" ,"US","Canada","Israel" };
@Override
protected void onCreate ( Bundle savedInstanceState ) {
super . onCreate ( savedInstanceState );
setContentView ( R . layout . activity_main );
Name = (EditText)findViewById(R.id.name);
Email = (EditText)findViewById(R.id.email);
Number = (EditText)findViewById(R.id.number);
submit = (Button)findViewById(R.id.submit);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name = Name.getText().toString();
String email = Email.getText().toString();
String number = Number.getText().toString();
Intent intent = new Intent(MainActivity.this,SecondActivity.class);
intent.putExtra("Name",name);
intent.putExtra("Email",email);
intent.putExtra("Number",number);
startActivity(intent);
}
});
Spinner spin = ( Spinner ) findViewById ( R . id . simplespinner );
spin . setOnItemSelectedListener ( this );
ArrayAdapter aa = new ArrayAdapter ( this , android . R . layout . simple_spinner_item , countryNames );
aa . setDropDownViewResource ( android . R . layout . simple_spinner_dropdown_item );
spin . setAdapter ( aa );
}
@Override
public void onItemSelected ( AdapterView <?> arg0 , View arg1 , int position , long id ) {
Toast . makeText ( getApplicationContext (), countryNames [ position ], Toast . LENGTH_LONG ). show ();
}
@Override
public void onNothingSelected ( AdapterView <?> arg0 ) {
}
}
SecondActivity.java:
public class SecondActivity extends Activity {
String Name;
String Email;
String Number;
TextView result;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
result = (TextView)findViewById(R.id.result);
Name = getIntent().getExtras().getString("Name");
Email = getIntent().getExtras().getString("Email");
Number = getIntent().getExtras().getString("Number");
result.setText("Name:"+" "+Name+'\n'+"Email:"+" "+Email+'\n'+"Number"+" "+Number);
}
}
Aucun commentaire:
Enregistrer un commentaire