久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

Android生成隨機數的方法實例

瀏覽:63日期:2022-09-20 13:39:29

本文實例為大家分享了Android生成隨機數的具體代碼,供大家參考,具體內容如下

java文件

package com.example.my_xm_bw_luowei;import android.os.Bundle;import android.util.Log;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.TextView;import androidx.appcompat.app.AppCompatActivity;import java.util.Random;public class MainActivity extends AppCompatActivity { private Button bt1; private EditText et1; private EditText et2; private TextView tv; private int i=0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); bt1 = (Button) findViewById(R.id.bt1); et2 = (EditText) findViewById(R.id.et2); tv = (TextView) findViewById(R.id.tv); bt1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {i++;String trim2 = et2.getText().toString().trim();String s = '';Random ran =new Random(System.currentTimeMillis());Log.d('aaa', 'onClick: '+i);for (int i = 0 ; i <1; i++) { s = s + 'n' + ran.nextInt(Integer.parseInt(trim2));}tv.setText(s+'');if (i==10){ tv.setText('直接讓高金玉上 嘻嘻嘻');} } }); }}

xml文件

<?xml version='1.0' encoding='utf-8'?><LinearLayout xmlns:android='http://schemas.android.com/apk/res/android' xmlns:app='http://schemas.android.com/apk/res-auto' xmlns:tools='http://schemas.android.com/tools' android:layout_width='match_parent' android:layout_height='match_parent' tools:context='.MainActivity' android:orientation='vertical' > <Button android:text='高金玉' android: android:background='#ffffff' android:layout_width='wrap_content' android:layout_height='wrap_content'></Button> <EditText android: android:hint='0-n' android:layout_width='match_parent' android:layout_height='wrap_content'></EditText> <TextView android:textColor='#DD0D0D' android:textSize='50dp' android: android:text='0' android:layout_width='wrap_content' android:layout_height='wrap_content'></TextView></LinearLayout>

效果圖片

Android生成隨機數的方法實例

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Android
相關文章:
主站蜘蛛池模板: 琼中| 永康市| 墨竹工卡县| 鄂州市| 屯门区| 子长县| 阿坝| 邢台市| 施秉县| 汨罗市| 涟源市| 浦江县| 都匀市| 齐河县| 淮北市| 彩票| 庆阳市| 民县| 板桥市| 大渡口区| 商城县| 囊谦县| 即墨市| 达州市| 张北县| 开封市| 岑溪市| 绿春县| 大洼县| 盘山县| 新邵县| 怀集县| 马关县| 武川县| 伊金霍洛旗| 旌德县| 嘉定区| 汾阳市| 龙里县| 依安县| 崇文区|