您的位置:首页 > 其它

按钮,alert,EditText

2015-08-03 16:53 309 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/C__CHM/article/details/47258709

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;
}
}


}



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: