【发布时间】:2021-07-31 18:01:37
【问题描述】:
在 Firebase 中,我需要 Parsing2,其中 1-video、2- 发布日期、3-流派、4-publisher、5-img、6-img2、7-title、8-description、9- developer、10-url链接,11-14 个标签,15 个价格。我需要在随机对象(0,n)中获取title和img
描述获取内容的类
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;
}}
需要实现从firebase获取数据并做随机方法的随机游戏类
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;
}
}}
【问题讨论】:
标签: java android firebase firebase-realtime-database arraylist