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>

最新文章

  1. 神马玩意,EntityFramework Core 1.1又更新了?走,赶紧去围观
  2. Android okHttp网络请求之Retrofit+Okhttp+RxJava组合
  3. Smooth Mouse
  4. 【Alpha】Daily Scrum Meeting第四次
  5. [Python]记录详细调用堆栈的日志
  6. Jmeter组件2. Timer 定时器
  7. SQLserver临时表
  8. Python标准库:内置函数repr(object)
  9. CQOI2015 解题报告
  10. PHP开发人员对JAVA的WEB开发入门(初版-已废弃)
  11. jquery滚动条事件
  12. css绘制倒三角
  13. JavaScript对象添加、删除、修改对象的属性
  14. SSM框架整合环境构建——基于Spring4和Mybatis3
  15. [20190401]跟踪dbms_lock.sleep调用.txt
  16. 理解去中心化 稳定币 DAI
  17. Git——如何将本地项目提交至远程仓库
  18. http://blog.csdn.net/w_e_i_/article/details/70766035
  19. [qemu] qemu旧的net参数已经不再可用了,新的这样用。
  20. jsplumb流程器使用3--connector

热门文章

  1. 【Asp.net入门01】动态网站基础知识
  2. mysql 设置默认编码为 utf8
  3. P2424 约数和 &amp;&amp; 真丶除法分块
  4. 视音频数据处理入门:H.264视频码流解析
  5. ip地址、子网掩码、DNS的关系与区别
  6. LeetCode-330.Patching Array
  7. Android 利用 gson 将 json 转成 对象object 集合list
  8. nodejs出现events.js:72中抛出错误 Error: listen EADDRINUSE
  9. Xilinx Altera FPGA中的逻辑资源(Slices VS LE)比较
  10. Hadoop/Spark环境运行过程中可能遇到的问题或注意事项