1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| package com.example.administrator.activitytest;
import android.content.DialogInterface; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
private Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button); button.setOnClickListener(new ButtonListener()); }
class ButtonListener implements View.OnClickListener{ @Override public void onClick(View v){ Intent intent = new Intent(); intent.setClass(MainActivity.this,Main2Activity.class); EditText editText = (EditText)findViewById(R.id.editText); String name = editText.getText().toString(); intent.putExtra("com.example.administrator.activitytest.Name",name); startActivity(intent); } } }
|