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 的说法, 给用户一种 身临其境 的体 ...
随机推荐
- python与pycharm
什么叫自动化测试? 通俗来说,自动化测试就是通过写代码来帮我们测试软件.用来做自动化测试的语言很多,python,Java,php,Go,ruby等.而且软件系统开发语言与自动化测试语言可以不一致.例 ...
- [Linux]-Linux常用命令之文件解压
不压缩方式压缩的文件需要不同的命令来解压缩,下面是Linux的各种文件解压命令. 对于.tar结尾的文件: tar -xf 对于.gz结尾的文件 : gzip -d all.gz gunzip all ...
- 【记录】css样式
记录css的样式设置,方便以后使用. 1.绝对定位,自适应父级大小css: .search-icon-delete { background: url('../../assets/images/sea ...
- Android 6.0 7.0 8.0 一个简单的app内更新版本-okgo app版本更新
登陆时splash初始页调用接口检查app版本.如有更新,使用okGo的文件下载,保存到指定位置,调用Android安装apk. <!-- Android 8.0 (Android O)为了针对 ...
- 2015/12/12 考了PAT,又回来玩Python了。
上次写飞机大战的坑还没填完,然后就有好长时间没有更新博客了.可能大家在疑惑我在干什么... 其实不是有意暂停博客更新的,十一月学校里有两个考试要准备,然后有好多实验要做.平时的课余时间本来就不是很多了 ...
- 20165230 2017-2018-2 《Java程序设计》第5周学习总结
20165230 2017-2018-2 <Java程序设计>第5周学习总结 教材学习内容总结 第七章 内部类与异常类 内部类与外嵌类 可以在类中定义另一个类,即内部类 包含内部类的类为内 ...
- pre,html转义,abbr缩写,表格table
<pre></pre>预定义文本标签pre(保留换行和空格) <sdds>对html转义 <abbr title="sddsdsds"&g ...
- Python爬虫---requests库快速上手
一.requests库简介 requests是Python的一个HTTP相关的库 requests安装: pip install requests 二.GET请求 import requests # ...
- Flask:操作SQLite3(0.1)
Windows 10家庭中文版,Python 3.6.4,Flask 1.0.2 本文介绍了第一次在Flask框架中操作SQLite3数据库的测试,参考了官网的文档Using SQLite 3 wit ...
- Python开发环境(2):启动Eclipse时检测到PYTHONPATH发生改变
OS:Windows 10家庭中文版,Eclipse:Oxygen.1a Release (4.7.1a),PyDev:6.3.2 4月25日,在Eclipse上安装了PyDev(前面博文有记录),并 ...