标签:
package com.example.wang.testapp2; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import java.util.Random; public class ZuoyeActivity extends AppCompatActivity { Button bt_2; Button bt_3; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_zuoye); bt_2=(Button)findViewById(R.id.bt_2); bt_3=(Button)findViewById(R.id.bt_3); } // public void bt1_OnClick(View v) { String string=""; Random random = new Random(); final String[] str =new String[6]; for(int i=0;i<6;i++) { int t=random.nextInt(9); str[i]=String.valueOf(t); string=string+str[i]; } if (str[0]=="0") { str[0]=String.valueOf(random.nextInt(9)); string=str[0]+str[1]+str[2]+str[3]+str[4]+str[5]; } Log.e("TAG", "string=" + string); View view=View.inflate(this,R.layout.activity_zuoye2,null); final AlertDialog alertDialog = new AlertDialog.Builder(this) .setTitle("生成最大值和最小值") .setView(view) .setPositiveButton("最小值", new DialogInterface.OnClickListener() { String string1=""; @Override public void onClick(DialogInterface dialog, int which) { AlertDialog al =(AlertDialog)dialog; int[] a = new int[6]; for (int i = 0; i < 6; i++) { a[i] = Integer.parseInt(str[i]); Log.e("TAG","a[}="+a[i]); } for (int i = 0; i < 6; i++) { for (int j = 0; j < 5-i; j++) { if (a[j] > a[j + 1]) { int b = a[j]; a[j] = a[j + 1]; a[j + 1] = b; } } } for (int i = 0; i < 6; i++) { str[i]=String.valueOf(a[i]); string1=string1+str[i]; } Intent intent=new Intent(ZuoyeActivity.this,ZuoyeActivity3.class); //intent.setData(Uri.parse(string1)); intent.putExtra("jieguo",string1); startActivity(intent); // EditText et_jieguo=(EditText)al.findViewById(R.id.et_jieguo); // // et_jieguo.setText(string1); } }) .setNegativeButton("最大值", null) .show(); EditText et_suiji=(EditText)alertDialog.findViewById(R.id.et_suiji); et_suiji.setText(string); } public void bt2_OnClick(View v) { final AlertDialog alertDialog=new AlertDialog.Builder(this) .setTitle("提示") .setMessage("确定要删除吗?" + "\n" + "要删除,请点击“是”。") .setNegativeButton("否", null) .setPositiveButton("是", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(ZuoyeActivity.this, "删除成功" + which, Toast.LENGTH_SHORT).show(); } }) .show(); } public void bt3_OnClick(View v) { View view=View.inflate(this, R.layout.activity_zuoye1, null); new AlertDialog.Builder(this) .setTitle("请输入电话号码") .setView(view) .setNeutralButton("拨出此号码", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { AlertDialog al = (AlertDialog) dialog; EditText et_1 = (EditText) al.findViewById(R.id.et_1); String str = et_1.getText().toString(); Intent intent = new Intent(Intent.ACTION_CALL); intent.setData(Uri.parse("tel:" + str)); try { startActivity(intent); } catch (Exception e) { e.printStackTrace(); } } }) .setPositiveButton("向此号码发短信", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { AlertDialog al=(AlertDialog)dialog; EditText et_1 = (EditText) al.findViewById(R.id.et_1); String str = et_1.getText().toString(); Intent intent = new Intent(Intent.ACTION_SENDTO); intent.setData(Uri.parse("smsto:"+str)); startActivity(intent); } }) .show(); } }
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.wang.testapp2.ZuoyeActivity3"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:id="@+id/et_jieguo" /> </RelativeLayout>
package com.example.wang.testapp2; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.EditText; public class ZuoyeActivity3 extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_zuoye3); EditText et_jieguo=(EditText)findViewById(R.id.et_jieguo); Intent intent=getIntent(); String s=intent.getStringExtra("jieguo"); et_jieguo.setText(s); } }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="练习题1" android:id="@+id/bt_1" android:onClick="bt1_OnClick"/> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="练习题2" android:id="@+id/bt_2" android:onClick="bt2_OnClick"/> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="练习题3" android:id="@+id/bt_3" android:onClick="bt3_OnClick"/> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="30dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="随机数:" android:textSize="25sp"/> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/et_suiji" /> </LinearLayout> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:id="@+id/et_jieguo" /> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.wang.testapp2.ZuoyeActivity3"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:id="@+id/et_jieguo" /> </RelativeLayout>
标签:
原文地址:http://www.cnblogs.com/wangchuanqi/p/5492158.html