Generate Random String Using Org.Apache.Commons.Lang3.Randomstringutils

Posted on

This representative demonstrate how to generate random String using org.apache.commons.lang3.RandomStringUtils.

You convey to download Apache Commons Lang, too add together the jounce to Android Studio Project’s libs. Refer to the video.

package com.blogspot.android_er.androidrandomstring;  import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.TextView;  import org.apache.commons.lang3.RandomStringUtils;  world cast MainActivity extends AppCompatActivity {      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);          Button btnGenerate = (Button)findViewById(R.id.gen);         in conclusion TextView textResult = (TextView)findViewById(R.id.result);          btnGenerate.setOnClickListener(new View.OnClickListener() {             @Override             world void onClick(View v) {                 textResult.setText("");                 for(int i=1; i<20; i++){                     String randomString = RandomStringUtils.randomAlphabetic(i) + "\n";                     textResult.append(randomString);                 }             }         });      } }  

<?xml version="1.0" encoding="utf-8"?> <LinearLayout     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="16dp"     android:orientation="vertical"     tools:context="com.blogspot.android_er.androidrandomstring.MainActivity">      <TextView         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_gravity="center_horizontal"         android:autoLink="web"         android:text="https://rootandroid.org//"         android:textStyle="bold" />      <Button         android:id="@+id/gen"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:text="Generate Random Strings"/>      <TextView         android:id="@+id/result"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:typeface="monospace"         android:textSize="22sp"/> </LinearLayout>