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>

android练习的更多相关文章

  1. 【原】Android热更新开源项目Tinker源码解析系列之三:so热更新

    本系列将从以下三个方面对Tinker进行源码解析: Android热更新开源项目Tinker源码解析系列之一:Dex热更新 Android热更新开源项目Tinker源码解析系列之二:资源文件热更新 A ...

  2. 配置android sdk 环境

    1:下载adnroid sdk安装包 官方下载地址无法打开,没有vpn,使用下面这个地址下载,地址:http://www.android-studio.org/

  3. Android SwipeRefreshLayout 下拉刷新——Hi_博客 Android App 开发笔记

    以前写下拉刷新 感觉好费劲,要判断ListView是否滚到顶部,还要加载头布局,还要控制 头布局的状态,等等一大堆.感觉麻烦死了.今天学习了SwipeRefreshLayout 的用法,来分享一下,有 ...

  4. Android Studio配置 AndroidAnnotations——Hi_博客 Android App 开发笔记

    以前用Eclicps 用习惯了现在 想学学 用Android Studio 两天的钻研终于 在我电脑上装了一个Android Studio 并完成了AndroidAnnotations 的配置. An ...

  5. Android请求网络共通类——Hi_博客 Android App 开发笔记

    今天 ,来分享一下 ,一个博客App的开发过程,以前也没开发过这种类型App 的经验,求大神们轻点喷. 首先我们要创建一个Andriod 项目 因为要从网络请求数据所以我们先来一个请求网络的共通类. ...

  6. 【原】Android热更新开源项目Tinker源码解析系列之一:Dex热更新

    [原]Android热更新开源项目Tinker源码解析系列之一:Dex热更新 Tinker是微信的第一个开源项目,主要用于安卓应用bug的热修复和功能的迭代. Tinker github地址:http ...

  7. 【原】Android热更新开源项目Tinker源码解析系列之二:资源文件热更新

    上一篇文章介绍了Dex文件的热更新流程,本文将会分析Tinker中对资源文件的热更新流程. 同Dex,资源文件的热更新同样包括三个部分:资源补丁生成,资源补丁合成及资源补丁加载. 本系列将从以下三个方 ...

  8. Android Studio 多个编译环境配置 多渠道打包 APK输出配置

    看完这篇你学到什么: 熟悉gradle的构建配置 熟悉代码构建环境的目录结构,你知道的不仅仅是只有src/main 开发.生成环境等等环境可以任意切换打包 多渠道打包 APK输出文件配置 需求 一般我 ...

  9. JS调用Android、Ios原生控件

    在上一篇博客中已经和大家聊了,关于JS与Android.Ios原生控件之间相互通信的详细代码实现,今天我们一起聊一下JS调用Android.Ios通信的相同点和不同点,以便帮助我们在进行混合式开发时, ...

  10. Android UI体验之全屏沉浸式透明状态栏效果

    前言: Android 4.4之后谷歌提供了沉浸式全屏体验, 在沉浸式全屏模式下, 状态栏. 虚拟按键动态隐藏, 应用可以使用完整的屏幕空间, 按照 Google 的说法, 给用户一种 身临其境 的体 ...

随机推荐

  1. python 启航

    first = 1while first<=9: sec = 1        while sec <= first:        print(  str(sec)+"*&qu ...

  2. UITextView默认文字提示

    在UITextField中自带placeholder属性,可以用于提示输入框信息.但是UITextView并不具备此功能介绍两种方法来实现:第一种:初始化UITextView//首先定义UITextV ...

  3. git爬坑不完全指北(一):Permission to xxx.git denied to user的解决方案

    由于对之前github账户名不太满意,又不像大神一样需要两个账号绑定.所以今天注册了新账号,想把电脑绑定到新账号上,结果就踩坑了……报错如标题. 在网上按照这个题目可以搜索出一大堆的解决方案,但都是一 ...

  4. call 大佬 help7——kmp 补齐 循环节

    http://acm.hdu.edu.cn/showproblem.php?pid=3746 用kmp算法,那么 但是也等于上面的是正确的 也等于下面是错误的 why? #include<cst ...

  5. Java并发编程原理与实战十六:AQS

    一.概述 谈到并发,不得不谈ReentrantLock:而谈到ReentrantLock,不得不谈AbstractQueuedSynchronized(AQS)! 类如其名,抽象的队列式的同步器,AQ ...

  6. bootstrap-tooltip+validate

    名称 返回类型 描述 validate(options) 返回:Validator 验证所选的FORM valid() 返回:Boolean 检查是否验证通过 rules() 返回:Options 返 ...

  7. 【Swift】UILabel的简单操作方法

    @IBAction func buttonClick_LabelCtrl(sender: AnyObject) { //定义CGRect来初始化UILable var frame: CGRect = ...

  8. JS对象中的原型

    对象的原型:每个对象都连接一个原型对象,并且它可以从中继承属性.所有通过对象字面量创建的对象都连接到object.prototype.当你创建一个新对象时,你可以选择某个对象作为它的原型.原型连接在更 ...

  9. 装好Linux后没有声音的看过来

    现代的Linux发行版对声卡的支持都应该没有问题.系统装好,声卡就应该正常工作. (尤其是ArchLinux,我觉得对硬件支持最跟得上时代步伐.) 可是我用mplayer播放mp3文件却没有声音,但也 ...

  10. kafka入门(3)- SpringBoot集成Kafka

    1.引入依赖 <dependency> <groupId>org.springframework.kafka</groupId> <artifactId> ...