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 的说法, 给用户一种 身临其境 的体 ...
随机推荐
- python3.6爬虫总结-01
1. HTTP 简介 HTTP常见状态码 200/OK: 请求成功 201/Created: 请求已被实现,且一个新资源已根据请求被建立,URI跟随Location头信息返回. 202/Accepte ...
- Window10+Python3.5安装opencv
Window10+Python3.5安装opencv 标签: opencvpython 2017-05-14 16:47 2201人阅读 评论(0) 收藏 举报 分类: Python编程(41) ...
- UITableViewCell在非Nib及Cell重用下设置CellStyle
在UITableViewController(实现了UITableViewDataSource)下需要实现 - (UITableViewCell *)tableView:(UITableView *) ...
- VS2010(32bit) + WIN7(64bit) 编译出不同平台程序版本
一.X86,即一般普通PC上跑的程序版本,不用修改工程属性 二.X64 1.设置工程平台---会在工程目录下生成 X64 文件夹 在工具栏--->生成--->配置管理器 窗口 设置“活动 ...
- bzoj千题计划171:bzoj2456: mode
http://www.lydsy.com/JudgeOnline/problem.php?id=2456 任意删除序列中两个不同的数,众数仍然是众数 不停的删,剩下的最后的数一定是众数 具体实现: 记 ...
- bzoj千题计划161:bzoj1589: [Usaco2008 Dec]Trick or Treat on the Farm 采集糖果
http://www.lydsy.com/JudgeOnline/problem.php?id=1589 tarjan缩环后拓扑排序上DP #include<cstdio> #includ ...
- bzoj千题计划150:bzoj2738: 矩阵乘法
http://www.lydsy.com/JudgeOnline/problem.php?id=2738 整体二分 二维树状数组累积 #include<cstdio> #include&l ...
- Seven Techniques for Data Dimensionality Reduction
Seven Techniques for Data Dimensionality Reduction Seven Techniques for Data Dimensionality Reductio ...
- 关于安装在win10上的oracle10g 兼容性问题
首先在安装过程中会出现一次报错,在安装的时候 安装好了以后,准备敲击命令如果出现闪退,即是兼容性问题,下面继续设置兼容性问题 然后右键----属性----兼容性,勾上以兼容性运行即可
- Javascript技术之详尽解析event对象
描述event代表事件的状态,例如触发event对象的元素.鼠标的位置及状态.按下的键等等.event对象只在事件发生的过程中才有效.event的某些属性只对特定的事件有意义.比如,fromEleme ...