lundi 10 mai 2021

Get random object from arraylist firebase

In Firebase i need Parsing2, where 1-video, 2- release date, 3-genre, 4-publisher, 5-img, 6-img2, 7-title, 8-description, 9- developer, 10-url link, 11-14 tags, 15-price. I need to get title and img in random object (0,n)

Class describing what to get

public class Random_game_texture {
String title;
String img;

public  Random_game_texture(String img, String title){
    this.title=title;
    this.img=img;
}

public void setTitle(String title) {
    this.title = title;
}

public void setImg(String img) {
    this.img = img;
}

public String getTitle() {
    return title;
}

public String getImg() {
    return img;
}}

Random game class where need realize get data from firebase and do random method

  public class Random_game extends AppCompatActivity implements View.OnClickListener{

  Button random_btn, link_btn;
  TextView title;
  ImageView img;
  DatabaseReference myRef;
  ArrayList<Random_game_texture> gamesList;
  Random randomGenerator;


@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_random_game);

    ImageButton Home = (ImageButton) findViewById(R.id.home);
    Home.setOnClickListener(this);
    ImageButton Lupa = (ImageButton) findViewById(R.id.lupa);
    Lupa.setOnClickListener(this);
    ImageButton Calendar = (ImageButton) findViewById(R.id.calendar);
    Calendar.setOnClickListener(this);
    ImageButton Kubik = (ImageButton) findViewById(R.id.kubik);
    Kubik.setOnClickListener(this);
    ImageButton Profile = (ImageButton) findViewById(R.id.profile);
    Profile.setOnClickListener(this);

    random_btn=findViewById(R.id.random_game);
    link_btn=findViewById(R.id.link_page);

    title=findViewById(R.id.name_random);
    img=findViewById(R.id.img_random);

    myRef = FirebaseDatabase.getInstance().getReference();
    gamesList=new ArrayList<>();




    random_btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {


        }
    });

}


@Override
public void onClick(View v) {
    switch (v.getId()){
        case R.id.home:
            startActivity(new Intent(this, News.class));
            break;
        case R.id.lupa:
            startActivity(new Intent(this, Games.class));
            break;
        case R.id.calendar:
            startActivity(new Intent(this, Calendar.class));
            break;
        case R.id.kubik:
            startActivity(new Intent(this, Random_game.class));
            break;
        case R.id.profile:
            startActivity(new Intent(this, Profile.class));
            break;
    }
}}



Aucun commentaire:

Enregistrer un commentaire