android练习
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练习的更多相关文章
- 【原】Android热更新开源项目Tinker源码解析系列之三:so热更新
本系列将从以下三个方面对Tinker进行源码解析: Android热更新开源项目Tinker源码解析系列之一:Dex热更新 Android热更新开源项目Tinker源码解析系列之二:资源文件热更新 A ...
- 配置android sdk 环境
1:下载adnroid sdk安装包 官方下载地址无法打开,没有vpn,使用下面这个地址下载,地址:http://www.android-studio.org/
- Android SwipeRefreshLayout 下拉刷新——Hi_博客 Android App 开发笔记
以前写下拉刷新 感觉好费劲,要判断ListView是否滚到顶部,还要加载头布局,还要控制 头布局的状态,等等一大堆.感觉麻烦死了.今天学习了SwipeRefreshLayout 的用法,来分享一下,有 ...
- Android Studio配置 AndroidAnnotations——Hi_博客 Android App 开发笔记
以前用Eclicps 用习惯了现在 想学学 用Android Studio 两天的钻研终于 在我电脑上装了一个Android Studio 并完成了AndroidAnnotations 的配置. An ...
- Android请求网络共通类——Hi_博客 Android App 开发笔记
今天 ,来分享一下 ,一个博客App的开发过程,以前也没开发过这种类型App 的经验,求大神们轻点喷. 首先我们要创建一个Andriod 项目 因为要从网络请求数据所以我们先来一个请求网络的共通类. ...
- 【原】Android热更新开源项目Tinker源码解析系列之一:Dex热更新
[原]Android热更新开源项目Tinker源码解析系列之一:Dex热更新 Tinker是微信的第一个开源项目,主要用于安卓应用bug的热修复和功能的迭代. Tinker github地址:http ...
- 【原】Android热更新开源项目Tinker源码解析系列之二:资源文件热更新
上一篇文章介绍了Dex文件的热更新流程,本文将会分析Tinker中对资源文件的热更新流程. 同Dex,资源文件的热更新同样包括三个部分:资源补丁生成,资源补丁合成及资源补丁加载. 本系列将从以下三个方 ...
- Android Studio 多个编译环境配置 多渠道打包 APK输出配置
看完这篇你学到什么: 熟悉gradle的构建配置 熟悉代码构建环境的目录结构,你知道的不仅仅是只有src/main 开发.生成环境等等环境可以任意切换打包 多渠道打包 APK输出文件配置 需求 一般我 ...
- JS调用Android、Ios原生控件
在上一篇博客中已经和大家聊了,关于JS与Android.Ios原生控件之间相互通信的详细代码实现,今天我们一起聊一下JS调用Android.Ios通信的相同点和不同点,以便帮助我们在进行混合式开发时, ...
- Android UI体验之全屏沉浸式透明状态栏效果
前言: Android 4.4之后谷歌提供了沉浸式全屏体验, 在沉浸式全屏模式下, 状态栏. 虚拟按键动态隐藏, 应用可以使用完整的屏幕空间, 按照 Google 的说法, 给用户一种 身临其境 的体 ...
随机推荐
- Qt ------ Q_UNUSED
Q_UNUSED(name) Indicates to the compiler that the parameter with the specified name is not used in t ...
- NATS_07:NATS之top工具监控以及测量调优工具
概述 你可以使用 nats-top 来实现类似于 linux 中 top 命令的实时监控 nats 服务: 可以使用 nats 提供的工具来进行针对性的调优. 安装nats-top $ go get ...
- [Java] I/O底层原理之一:字符流、字节流及其源码分析
关于 I/O 的类可以分为四种: 关于字节的操作:InputStream 和 OutPutStream: 关于字符的操作:Writer 和 Reader: 关于磁盘的操作:File: 关于网络的操作: ...
- PyQt4 里的表格部件的使用方法: QTableWidget
PyQt4 里的表格部件的使用方法: QTableWidget QT下QTableWidget使用方法小结 - - 博客频道 - CSDN.NET http://blog.csdn.net/jingz ...
- Linux下压缩文件-2
Linux下的压缩文件剖析 对于刚刚接触Linux的人来说,一定会给Linux下一大堆各式各样的文件名给搞晕.别个不说,单单就压缩文件为例,我们知道在Windows下最常见的压缩文件就只有两种,一是, ...
- 创建分区swap分区
1.将文件系统卸载 #umount /sdc5 2.创建swap分区 #mkswap /dev/sdc5 3.激活swap分区 #swapon -a /dev/sdc5 4.查看swap分区情况 #s ...
- thinkphp 带条件分页查询
thinkphp 带条件分页查询:form表单传值时候,method='get'. 用 get 传值
- C语言入门教程-(3)基本数据类型
1.数据类型 在C语言中,数据类型指的是用于声明不同类型的变量或函数的一个广泛的系统.C语言数据类型可以分为四种: 1.基本类型:它们是算术类型,包括两种类型:整数类型和浮点类型. 2.枚举类型:它们 ...
- 个人集群部署hadoop 2.7 + hive 2.1
环境:centos 6.6 x64 (学习用3节点) 软件:jdk 1.7 + hadoop 2.7.3 + hive 2.1.1 环境准备: 1.安装必要工具 yum -y install open ...
- Java 8 Lambda表达式,让你的代码更简洁
Lambda表达式是Java 8一个非常重要的新特性.它像方法一样,利用很简单的语法来定义参数列表和方法体.目前Lambda表达式已经成为高级编程语言的标配,像Python,Swift等都已经支持La ...