小程序:彩票机选神器 !
2015-11-18 21:18
726 查看
package com.lixu.caipiao; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class MainActivity extends Activity implements OnClickListener { Button btn1; Button btn2; Button btn3; EditText et1; EditText et2; EditText et3; StringBuffer sb; StringBuffer sb2; StringBuffer sb3; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn1 = (Button) findViewById(R.id.btn1); btn2 = (Button) findViewById(R.id.btn2); btn3 = (Button) findViewById(R.id.btn3); et1 = (EditText) findViewById(R.id.et1); et2 = (EditText) findViewById(R.id.et2); et3 = (EditText) findViewById(R.id.et3); btn1.setOnClickListener(this); btn2.setOnClickListener(this); btn3.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.btn1: sb = new StringBuffer(); shuang(); et1.setText(sb); break; case R.id.btn2: sb2 = new StringBuffer(); daletou(); et2.setText(sb2); break; case R.id.btn3: sb3 = new StringBuffer(); qixing(); et3.setText(sb3); break; default: break; } } public void shuang() { int[] a = new int[7]; int i = 0; while (i < 6) { int b = (int) (Math.random() * 33) + 1; boolean temp = true; for (int m = 0; m < a.length - 1; m++) { if (a[m] == b) { temp = false; } } if (!temp) { continue; } a[i] = b; i++; } for (int l = 0; l < a.length - 1; l++) { for (int h = 0; h < a.length - 1; h++) { if (a[l] < a[h]) { int temp = a[l]; a[l] = a[h]; a[h] = temp; } } } int k = (int) (Math.random() * 16) + 1; a[6] = k; for (int n : a) { sb.append(n + ","); } } public void daletou() { int[] a = new int[7]; int i = 0; while (i < 5) { int b = (int) (Math.random() * 35) + 1; boolean temp = true; for (int e = 0; e < a.length - 2; e++) { if (a[e] == b) { temp = false; } } if (!temp) { continue; } a[i] = b; i++; } for (int m = 0; m < a.length - 2; m++) { for (int n = m + 1; n < a.length - 2; n++) { if (a[m] > a ) { int temp1 = a[m]; a[m] = a ; a = temp1; } } } while (i > 4 && i < 7) { int k = (int) (Math.random() * 12) + 1; boolean temp2 = true; for (int e = 5; e < 7; e++) { if (a[e] == k) { temp2 = false; } } if (!temp2) { continue; } a[i] = k; i++; } for (int m = 5; m < 7; m++) { for (int n = m + 1; n < 7; n++) { if (a[m] > a ) { int temp1 = a[m]; a[m] = a ; a = temp1; } } } for (int n : a) { sb2.append(n + ","); } } public void qixing() { int[] a = new int[7]; for (int j = 0; j < 7; j++) { int b = (int) (Math.random() * 10); a[j] = b; } for (int n : a) { sb3.append(n + ","); } } }
xml文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/RelativeLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.lixu.caipiao.MainActivity" > <EditText android:id="@+id/et1" android:layout_width="210dp" android:layout_height="50dp" android:hint="等待输入" android:background="@drawable/round"/> <EditText android:id="@+id/et2" android:layout_width="210dp" android:layout_height="50dp" android:layout_below="@id/et1" android:hint="等待输入" android:background="@drawable/round" /> <EditText android:id="@+id/et3" android:layout_width="210dp" android:layout_height="50dp" android:layout_below="@id/et2" android:hint="等待输入" android:background="@drawable/round"/> <Button android:id="@+id/btn1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:text="双色球机选" android:background="@drawable/round"/> <Button android:id="@+id/btn2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/et2" android:layout_alignBottom="@+id/et2" android:layout_alignParentRight="true" android:text="大乐透机选" android:background="@drawable/round"/> <Button android:id="@+id/btn3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_below="@+id/btn2" android:text="七星彩机选" android:background="@drawable/round"/> </RelativeLayout>
运行效果图:
相关文章推荐
- 微信支付时body有中文无法支付出现签名错误问题
- [ZZ]SAE微信公众号PHP SDK, token一直验证失败
- 搜狗微信搜索采集
- 仿微信 发起群聊 类似样式
- 微信开发总结小站
- 创客路上,跟着嘻多猴快乐出发!
- 微信公众账号基础开发介绍一之百度云服务器使用
- ListView具有多种item布局——实现微信对话列
- Java微信开发之公众号支付接口
- 关于java过滤微信emoji表情的问题解决方法
- iOS ShareSDK如果没有安装微信,QQ点击按钮没反应,上线有可能会被苹果拒绝.
- 一次失败的微信运营活动(实际上是一个很有参考意义的产品策划经验)
- C# 微信公众平台开发(2)-- 微信菜单
- 航空IT生活圈(微信号:Air-IT ) 微信订阅还不错
- 微信内移动前端开发抓包调试工具fiddler使用教程
- Android微信支付遇到的坑
- 仿微信下拉录制视频
- 对微信的二次打包学习1:重打包
- 反编译微信dex
- android 微信登录