APP HIGHEST MOUNTAIN NAME
JAVA FILE
JAVA FILE
package com.example.viraj.apphighestmountain; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; import java.util.Random; public class MainActivity extends AppCompatActivity { private Button b1; private TextView t1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); b1=(Button)findViewById(R.id.id_button); t1=(TextView)findViewById(R.id.id_text_generator); final String [] mountain={"rone","rtwo","rthree","rfour","rfive","rsix","rseven"}; b1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Random r1=new Random(); int randomname=r1.nextInt(mountain.length);//mountin to length is 0 to all numbert1.setText(mountain[randomname]);//example mountain[2] where 2 - rthree } }); } }
XML FILE
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout 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="com.example.viraj.apphighestmountain.MainActivity"> <Button android:id="@+id/id_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" android:layout_marginTop="100dp" android:text="RANDOM NAME GENERATE" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <TextView android:id="@+id/id_text_generator" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" android:layout_marginTop="116dp" android:text="NAME " android:textSize="30dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/id_button" /> </android.support.constraint.ConstraintLayout>
0 comments:
Post a Comment