activity_main XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="手机号" />
<EditText
android:id="@+id/edit_text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入手机号"
/>
<TextView
android:id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="手机号" />
<EditText
android:id="@+id/edit_text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入手机号"
/>
<TextView
android:id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="本机手机号" />
<EditText
android:id="@+id/edit_text3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入本机手机号"
/>
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="注册"
/>
</LinearLayout>
MainActivity:
public class MainActivity extends Activity implements OnClickListener{
private Button button;
private EditText editText1;
private EditText editText2;
private EditText editText3;
private ArrayAdapter<String> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1);
button=(Button) findViewById(R.id.button);
editText1=(EditText) findViewById(R.id.edit_text1);
editText2=(EditText) findViewById(R.id.edit_text2);
editText3=(EditText) findViewById(R.id.edit_text3);
button.setOnClickListener(this);
}
@Override
public void onClick(View v){
switch(v.getId()){
case R.id.button:
// 在此添加逻辑
AlertDialog.Builder dialog=new AlertDialog.Builder(MainActivity.this);
dialog.setTitle("打印");
String inputText1=editText1.getText().toString();
String inputText2=editText2.getText().toString();
String inputText3=editText3.getText().toString();
dialog.setMessage(inputText1+'\n'+inputText2+'\n'+inputText3);
dialog.show();
break;
default:
break;
}
}
}