I a making a Bingo or Tambola or Housie game app...Where whenever the user clicks on generate the number button then it should get the random number and send it to activity b (or the board.java) so that in that activity(board) it will take it and highlight it so that when the users want to check the board, he could go to that activity through button and see which all numbers have been done... Here I don't know how to do it
and this is the Main activity code;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class NumberActivity extends AppCompatActivity
{
ImageView ivBoard, ivGenerate;
TextView tvNumber;
public int randomNumber;
public int count = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_number);
ivBoard = findViewById(R.id.ivBoard);
ivGenerate = findViewById(R.id.ivGnn);
tvNumber = findViewById(R.id.tvNumber);
final Integer[] numbers = new Integer[90];
for (int i = 0; i < 90; i++) {
numbers[i] = i+1;
}
final Intent activityIntent;
List<Integer> integerList = Arrays.asList(numbers);
Collections.shuffle(integerList);
integerList.toArray(numbers);
randomNumber = numbers[count];
count++;
ivBoard.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
Intent intent = new Intent(NumberActivity.this, com.example.fullhouse.Board.class);
startActivity(intent);
}
});
ivGenerate.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
randomNumber = numbers[count];
System.out.println(randomNumber);
count++;
Intent intent = new Intent(NumberActivity.this, com.example.fullhouse.Board.class);
intent.putExtra("number", randomNumber);
// if (activityIntent != null) {
// startActivity(activityIntent);
// } else {
// // show error that user didn't clicked on ivBoard via Toast or some logic
// }
}
});
}
}
If needed let me know to add any other code or thing I respect your answer, Thanks