当用户登录时,我该如何fetch
从用户外部获取数据?
我以用户身份登录时无法获取数据。 。 帮助任何人?检查图像。谢谢 希望你们能提供帮助。我使用mref进行了调用,但是我无法将数据从外部获取,我认为他正在查看登录数据的用户。但是数据在外面。谢谢你希望你们能帮助我
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin);
//drawer for menu
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer);
mToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.open, R.string.close);
mDrawerLayout.addDrawerListener(mToggle);
mToggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
NavigationView navigationView =(NavigationView)findViewById(R.id.navigation_view);
navigationView.setNavigationItemSelectedListener(this);
ActionBar actionBar = getSupportActionBar();
//Set title
actionBar.setTitle("BFP Announcements");
mSharedPref = getSharedPreferences("SortSettings", MODE_PRIVATE);
String mSorting = mSharedPref.getString("Sort", "newest"); //where if no settings is selected newest will be default
//since default value is newest , the newest will be displayed
if (mSorting.equals("newest")){
mLayoutManager = new LinearLayoutManager(this);
//this will load the items from bottom means newest first
mLayoutManager.setReverseLayout(true);
mLayoutManager.setStackFromEnd(true);
}
else if (mSorting.equals("oldest")){
mLayoutManager = new LinearLayoutManager(this);
//this will load the items from bottom means oldest first
mLayoutManager.setReverseLayout(false);
mLayoutManager.setStackFromEnd(false);
}
//RecyclerView
mRecyclerView = findViewById(R.id.recyclerView);
mRecyclerView.setHasFixedSize(true);
//set Layout as Linear
mRecyclerView.setLayoutManager(mLayoutManager);
//send Query to firebasedatabase
mFirebaseDatabase = FirebaseDatabase.getInstance();
mRef = mFirebaseDatabase.getReference("Data");
}
//search data
private void firebaseSearch(String searchText){
//convert string entered in searchview to lowercase
String query = searchText.toLowerCase();
Query firebaseSearchQuery = mRef.orderByChild("search").startAt(query).endAt(query + "\uf8ff");
FirebaseRecyclerAdapter<Model, ViewHolder> firebaseRecyclerAdapter =
new FirebaseRecyclerAdapter<Model, ViewHolder>(
Model.class,
R.layout.row,
ViewHolder.class,
firebaseSearchQuery
) {
@Override
protected void populateViewHolder(ViewHolder viewHolder, Model model, int position) {
viewHolder.setDetails(getApplicationContext(), model.getTitle(), model.getDescription(), model.getImage());
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
ViewHolder viewHolder = super.onCreateViewHolder(parent, viewType);
viewHolder.setOnClickListener(new ViewHolder.ClickListener() {
@Override
public void onItemClick(View view, int position) {
//Views
TextView mTitleTv = view.findViewById(R.id.rTitleTv);
TextView mDescTv = view.findViewById(R.id.rDescriptionTv);
ImageView mImageView = view.findViewById(R.id.rImageView);
//get data from views
String mTitle = mTitleTv.getText().toString();
String mDesc = mDescTv.getText().toString();
Drawable mDrawable = mImageView.getDrawable();
Bitmap mBitmap = ((BitmapDrawable)mDrawable).getBitmap();
//pass this data to new activity
Intent intent = new Intent(view.getContext(), PostDetailActivity.class);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
mBitmap.compress(Bitmap.CompressFormat.PNG, 100,stream);
byte[] bytes = stream.toByteArray();
intent.putExtra("image", bytes); //put bitmap image as array
intent.putExtra("title", mTitle); //put title
intent.putExtra("description", mDesc); //put description
startActivity(intent); //start activity
}
@Override
public void onItemlongClick(View view, int position) {
//TODO do your own implementation on long item click
}
});
return viewHolder;
}
};
//set adapter to recyclerView
mRecyclerView.setAdapter(firebaseRecyclerAdapter);
}