我有一个问题,我想访问数组列表并显示recyclerview中包含的内容,任何人都可以帮助我
public class Myadapter extends FirebaseRecyclerAdapter<search_model,Myadapter.SearchViewHolder>{
DatabaseReference reference1;
private List<search_model> exampleList;
private ArrayList<search_model> exampleListFull;
Query query1;
String ValueDatabase;
String refinedData;
private ArrayList<String> namesCity;
FirebaseDatabase database;
String item;
FirebaseAuth mAuth1;
String usersId1;
DatabaseReference reference;
private ArrayList<String> requestList = new ArrayList<>();;
final ArrayList<String> requestList2 = new ArrayList<>();
public Myadapter(@NonNull FirebaseRecyclerOptions<search_model> options) {
super(options);
}
protected void onBindViewHolder(@NonNull SearchViewHolder holder, final int position, @NonNull final search_model model) {
holder.fullName.setText(model.getFullName());
holder.Sign_up_as.setText(model.getSign_up_as());
holder.Languages.setText(model.getLanguages());
holder.City.setText(model.getCity().toString());
if(model.getpayment()!=null){
holder.salary.setText(model.getpayment()+""+"$/Day");}
Glide.with(holder.profile_images.getContext()).load(model.getProfile_images()).into(holder.profile_images);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String visit_user_id = getRef(position).getKey();
Context context = v.getContext();
Intent profileintent = new Intent(context, tourguide_request.class);
profileintent.putExtra("visit_user_id", visit_user_id);//tourist
context.startActivity(profileintent);
}
});
}
@NonNull
@Override
public SearchViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.singlerow, parent, false);
return new SearchViewHolder(view);
}
class SearchViewHolder extends RecyclerView.ViewHolder {
String item = "";
String signUpas;
CircleImageView profile_images;
TextView fullName,Languages, Sign_up_as,salary,City;
FirebaseDatabase database;
public SearchViewHolder(@NonNull View itemView) {
super(itemView);
database = FirebaseDatabase.getInstance();
// query1 = reference1.orderByChild("Languages");
profile_images=(CircleImageView)itemView.findViewById(R.id.profile_images);
fullName=(TextView)itemView.findViewById(R.id.fullName);
Languages=(TextView)itemView.findViewById(R.id.Languages);
Sign_up_as=(TextView)itemView.findViewById(R.id.Sign_up_as);
City=(TextView)itemView.findViewById(R.id.City);
salary=(TextView)itemView.findViewById(R.id.salary);
signUpas = Sign_up_as.getText().toString();
}}}
这是recyclerview的适配器类
public class Search extends Fragment {
RecyclerView recview;
Myadapter adapter;
private Toolbar mtoolbar;
private String reciever_id,sender_user_id,current_state;
private CircularImageView visit_profile;
private TextView visit_name,visit_status;
private Button request_button,decline_button;
private FirebaseAuth mauth;
DatabaseReference ref,chatrequestref,contactsRef,NotificationRef;
private List<search_model> examplelist;
private List<search_model> examplelistfull;//copy of the first list because when we hitted the first list we will remove the item from it and when we remove it from the input field we store it in this list
DatabaseReference reference,reference1;
Query query,query1,query2;
private Toolbar toolbar;
String ValueDatabase;
String refinedData;
private ArrayList<search_model> mSearchItems;
ArrayList <search_model> List;
private String[] SearchIndex;
FirebaseDatabase database;
String item;
FirebaseAuth mAuth1;
String usersId1;
final ArrayList<String> requestList = new ArrayList<>();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View view = inflater.inflate(R.layout.activity_serach, container, false);
setHasOptionsMenu(true);
toolbar=view.findViewById(R.id.toolbar);
((AppCompatActivity)getActivity()).setSupportActionBar(toolbar);
// mSearchView = (SearchView)view.findViewById(R.id.search_view);
recview=(RecyclerView)view.findViewById(R.id.recview);
recview.setLayoutManager(new LinearLayoutManager(getActivity()));
recview.setItemAnimator(new DefaultItemAnimator());
reference = FirebaseDatabase.getInstance().getReference("Users");
query = reference.orderByChild("Sign_up_as").equalTo("Tour Guide");
FirebaseRecyclerOptions<search_model> options =
new FirebaseRecyclerOptions.Builder<search_model>().setQuery(query, search_model.class).build();
// Query cityQuery = reference.orderByChild("City");
adapter=new Myadapter(options);
recview.setAdapter(adapter);
adapter.startListening();
return view;
}
/* @Override
public void onStart() {
super.onStart();
// reference.child("userState").child("state").setValue("offline");
}*/
@Override
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
// menu.clear();
inflater = getActivity().getMenuInflater();
inflater.inflate(R.menu.search, menu);
///here we want to create listener for our search view so we can add listener to it and filter our recycle view
MenuItem searchItem = menu.findItem(R.id.action_search);
//now we want to make reference for the search it self
SearchView searchView = (SearchView) searchItem.getActionView();
searchView.setQueryHint("Search Location..");
searchView.setMaxWidth(Integer.MAX_VALUE);
searchView.setIconifiedByDefault(false);
SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
// SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
// searchView.setSearchableInfo(
// MenuItemCompat.setShowAsAction(searchItem, MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW | MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
// MenuItemCompat.setActionView(searchItem, searchView);
searchView.setImeOptions(EditorInfo.IME_ACTION_DONE);//THIS will replace the search button in keyboard with appropriate one
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
processsearch(s);
return false;
}
@Override
public boolean onQueryTextChange(String s) {
processsearch(s);
// adapter.getFilter().filter(s);
return false;
}
});
super.onCreateOptionsMenu(menu,inflater);
}
private void processsearch(String s)
{
String queryy = s.toLowerCase();
reference1 = FirebaseDatabase.getInstance().getReference("Users");
query1 = reference1.orderByChild("City");
FirebaseRecyclerOptions<search_model> options =
new FirebaseRecyclerOptions.Builder<search_model>().setQuery(query1.startAt(s.toLowerCase()).endAt(s.toLowerCase()+"\uf8ff"), search_model.class).build();
adapter=new Myadapter(options);
adapter.startListening();
recview.setAdapter(adapter);
}
}
这是包含查询的搜索类
public class search_model {
String fullName;
String Languages;
String Sign_up_as;
String profile_images;
String item;
public String getItem() {
return item;
}
public void setItem(String item) {
this.item = item;
}
List<String> City;
String payment;
public search_model(String fullName,String Languages ,String Sign_up_as,String profile_images, String payment,List<String> City,String item) {
this.fullName = fullName;
this.Languages=Languages;
this.Sign_up_as=Sign_up_as;
this.profile_images = profile_images;
this.payment=payment;
this.City=City;
this.item=item;
}
public search_model(){
}
public String getpayment() {
return payment;
}
public void setpayment(String payment) {
this.payment = payment;
}
public String getProfile_images() {
return profile_images;
}
public void setProfile_images(String profile_images) {
this.profile_images = profile_images;
}
public String getSign_up_as() {
return Sign_up_as;
}
public void setSign_up_as(String Sign_up_as) {
Sign_up_as = Sign_up_as;
}
public String getLanguages() {
return Languages;
}
public void setLanguages(String languages) {
Languages = languages;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public List<String> getCity() {
return City;
}
public void setCity(List<String> city) {
City = city;
}
}
this my application searchview with recyclerview after run
我只想用逗号检索城市arraylist并将其显示在recyclerview中,如不带[]所示,我可以在所有arraylist中搜索我想要的城市,对不起我的英语不好,这是不是我的母语