最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android生成隨機(jī)數(shù)的方法實(shí)例

 更新時(shí)間:2021年03月22日 11:13:02   作者:你先去買飯  
這篇文章主要為大家詳細(xì)介紹了Android生成隨機(jī)數(shù)的方法實(shí)例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android生成隨機(jī)數(shù)的具體代碼,供大家參考,具體內(nèi)容如下

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:id="@+id/bt1"
    android:background="#ffffff"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"></Button>
  <EditText
    android:id="@+id/et2"
    android:hint="0-n"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"></EditText>
  <TextView
    android:textColor="#DD0D0D"
    android:textSize="50dp"
    android:id="@+id/tv"
    android:text="0"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"></TextView>
</LinearLayout>

效果圖片

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

城口县| 天峨县| 阿拉善左旗| 巍山| 荥经县| 岐山县| 常山县| 永定县| 金山区| 洪湖市| 中西区| 武川县| 庆阳市| 和静县| 北流市| 河间市| 湘潭市| 邳州市| 沁水县| 波密县| 禄丰县| 铁岭县| 牡丹江市| 陕西省| 新疆| 舒兰市| 蕉岭县| 河北区| 白山市| 武穴市| 麦盖提县| 新密市| 监利县| 雅江县| 庄浪县| 康定县| 三门县| 宁海县| 天长市| 察隅县| 广安市|