how can i sort firebase data according to their ratings after getting title of value vikas?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


how can i sort firebase data according to their ratings after getting title of value vikas?



Means I want to sort my firebaserecycleradapter according to highest no of ratings first after applying query on data having title with value "vikas"


firebaserecycleradapter



This is my code:


package com.onlinetuto;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
import com.onlinetuto.model.blog;

import static com.onlinetuto.EmptyActivity.EXTRA_POST_KEY;

public class GetLocation extends AppCompatActivity {

private static final String TAG = "MainActivity";
private RecyclerView re;
private DatabaseReference d,dref;
private FirebaseAuth mauth;
FirebaseRecyclerAdapter<blog,BlogViewholder> firebaseRecyclerAdapter;
DatabaseReference users, comments;
ProgressBar progressBar;
String locname;
SharedPreferences sharedPreferences;
LinearLayoutManager linearLayoutManager;
AutoCompleteTextView autoCompleteTextView;
Intent intent;
Button button;
Long code;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_get_location);
intent=getIntent();
if(intent!=null)
{
code= intent.getLongExtra("queryname",110094);
}
Toast.makeText(this, code.toString(), Toast.LENGTH_SHORT).show();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mauth = FirebaseAuth.getInstance();


d = FirebaseDatabase.getInstance().getReference().child("Products");

users = FirebaseDatabase.getInstance().getReference().child("Users");
comments = FirebaseDatabase.getInstance().getReference().child("post-comments");
Query nm=d.orderByChild("pincode").equalTo(code);
progressBar = (ProgressBar) findViewById(R.id.progress_bar);
progressBar.setVisibility(View.VISIBLE);
// mquery = dtop.orderByChild("title").equalTo("hul");
// mquery2 = dtop.orderByChild("likeCount").limitToFirst(100);
//for offline capabilities of database
// d3.keepSynced(true);
d.keepSynced(true);
// mdatabaselike.keepSynced(true);
re = (RecyclerView) findViewById(R.id.blog_list);
re.setHasFixedSize(true);
linearLayoutManager = new LinearLayoutManager(getApplicationContext());
linearLayoutManager.setReverseLayout(true);
linearLayoutManager.setStackFromEnd(true);
re.setLayoutManager(linearLayoutManager);


firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<blog, BlogViewholder>(
blog.class,
R.layout.blog_row,
BlogViewholder.class,
nm
) {
@Override
protected void populateViewHolder(final BlogViewholder viewHolder, final blog model, int position) {

final String post_key = getRef(position).getKey();
//for retrieving each post key getRef() method is used for this.
final DatabaseReference post_ref = getRef(position);
viewHolder.setTitle(model.getClassname());
viewHolder.setImage(getApplicationContext(), model.getImageone());
viewHolder.setReviews(model.getReviews());
viewHolder.setTypo(model.getType());
viewHolder.setNoofComments(model.getNoofreviews());
viewHolder.setratings(model.getNetrat());
viewHolder.setTextRating(model.getNoofreviews());
viewHolder.vi.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
Intent newIntent = new Intent(GetLocation.this, EmptyActivity.class);
newIntent.putExtra(EXTRA_POST_KEY, post_key);
newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
// newIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(newIntent);
}
});

progressBar.setVisibility(View.GONE);
}

};


re.setAdapter(firebaseRecyclerAdapter);

}
private Boolean exit = false;
@Override
public void onBackPressed() {
if (exit) {
finish(); // finish activity
} else {
Toast toast=Toast.makeText(this, "Press Back again to exit", Toast.LENGTH_SHORT);
View view = toast.getView();
view.setBackgroundColor(getResources().getColor(R.color.toa));
TextView text = (TextView) view.findViewById(android.R.id.message);
text.setTextColor(getResources().getColor(R.color.blackm));
/*Here you can do anything with above textview like text.setTextColor(Color.parseColor("#000000"));*/
toast.show();
exit = true;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
exit = false;
}
}, 2 * 1000);

}

}
public static class BlogViewholder extends RecyclerView.ViewHolder {
View vi;
FirebaseAuth mauth;
EditText e1;

public BlogViewholder(View itemView) {
super(itemView);
vi = itemView;

mauth = FirebaseAuth.getInstance();

}

/* public void setImage(Context context,String image){
ImageView imageView=(ImageView)vi.findViewById(R.id.post_iamge);
Picasso.with(context).load(image).into(imageView);

}*/
public void setTitle(String classname) {
TextView textView = (TextView) vi.findViewById(R.id.textViewTitle);
textView.setText(classname);
}
public void setImage(Context context, String image){
ImageView imageView=(ImageView)vi.findViewById(R.id.imageView);
Glide.with(context).load(image).into(imageView);
}
public void setReviews(String reviews) {
TextView textView = (TextView) vi.findViewById(R.id.reviews);
textView.setText(reviews);
}
public void setTypo(String type) {
TextView textView = (TextView) vi.findViewById(R.id.type);
textView.setText(type);


}
public void setTextRating(long comme) {
TextView textView = (TextView) vi.findViewById(R.id.textViewRating);
textView.setText(comme + "");


}
public void setNoofComments(long comme) {
TextView textView = (TextView) vi.findViewById(R.id.reviews);
textView.setText(comme+" Reviews");


}
public void setratings(Long rat) {
RatingBar textView = (RatingBar) vi.findViewById(R.id.img);
Integer myNum=0;

if(rat==null)
myNum=0;
else
{
Integer integer=(int)(long)rat;
myNum=integer;
}
if(myNum>5)
{
myNum=myNum%5;
textView.setRating(myNum);
}
else
{
textView.setRating(myNum);
}


}
}



}



this is my code please help me.i want to sort query data according to their ratings before passing it to the firebase recycleradapter .how can i acheive that?
Product database reference one key data:-
img1img2img3img4



i am using firebase realtime database here









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

'Series' object is not callable Error / Statsmodels illegal variable name