【发布时间】:2020-01-22 02:11:49
【问题描述】:
我对 firebase 很陌生,无法获取键值的内容。我尝试了几件事,但都没有成功。
谁能帮我获取数据吗?
我的 firebase 数据库 - Firebase 数据库结构:
我的代码 -
public class Dashboard extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
private Toolbar dashboard_toolbar;
private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mActionBarDrawerToggle;
private FirebaseAuth mAuth;
DatabaseReference rootRef, teacher, teacherPost;
String str;
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard);
/* str = (String) getIntent().getExtras().get("temp");*/
textView = (TextView) findViewById(R.id.institute_news);
mAuth = FirebaseAuth.getInstance();
dashboard_toolbar = (Toolbar) findViewById(R.id.dashboard_toolbar);
setSupportActionBar(dashboard_toolbar);
getSupportActionBar().setTitle("Dashboard");
dashboard_toolbar.setTitleTextColor(0xFFFFFFFF);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawable);
mActionBarDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, dashboard_toolbar, R.string.open, R.string.close);
mDrawerLayout.setDrawerListener(mActionBarDrawerToggle);
mDrawerLayout.addDrawerListener(mActionBarDrawerToggle);
mActionBarDrawerToggle.syncState();
dashboard_toolbar.post(new Runnable() {
@Override
public void run() {
Drawable d = ResourcesCompat.getDrawable(getResources(), R.drawable.actionmenu, null);
dashboard_toolbar.setNavigationIcon(d);
}
});
NavigationView navigationView = (NavigationView) mDrawerLayout.findViewById(R.id.navigationView);
navigationView.setNavigationItemSelectedListener(this);
rootRef = FirebaseDatabase.getInstance().getReference();
teacher = rootRef.child("admin").child("classPost");
teacherPost = teacher.child("post");
String mGroupId = teacherPost.push().getKey();
Toast.makeText(this, "" + teacherPost, Toast.LENGTH_SHORT).show();
textView.setText(mGroupId);
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawable);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.nav_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (mActionBarDrawerToggle.onOptionsItemSelected(item))
return true;
return super.onOptionsItemSelected(item);
}
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.aboutUs) {
} else if (id == R.id.help) {
} else if (id == R.id.report) {
} else if (id == R.id.logoutmenu) {
mAuth.signOut();
sendToStart();
} else if (id == R.id.setting) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawable);
drawer.closeDrawer(GravityCompat.START);
return true;
}
public void getAttendance(View view) {
Toast.makeText(this, "Attendance Details Apk Fire here", Toast.LENGTH_LONG).show();
}
public void trackChild(View view) {
Toast.makeText(this, "child tracker apk fire here Here", Toast.LENGTH_LONG).show();
}
public void getEwallet(View view) {
Toast.makeText(this, "Ewallet Apk Fire Here", Toast.LENGTH_LONG).show();
}
public void getHealth(View view) {
Toast.makeText(this, "Health apk fire here", Toast.LENGTH_LONG).show();
}
public void getMessageBoardDetails(View view) {
startActivity(new Intent(this,MessageBoard.class));
}
public void startChat(View view) {
startActivity(new Intent(this,Chat.class));
}
private void sendToStart() {
startActivity(new Intent(Dashboard.this,Start.class));
finish();
}
public void readMore(View view) {
startActivity(new Intent(this,InstituteMessageBoard.class));
}
}
【问题讨论】:
标签: java android firebase firebase-realtime-database