0

I have display multiple row in the RecyclerView and top of the one filter select the filter open the Spinner and select the Spinner item to open only selected list how to show
i m new in android programming

My class

private List<People> peolesListAll = new ArrayList<>();
private RecyclerView recyclerView;
private AlertAllCustomeAdapter alertAllCustomAdapter;
private DataBaseHelper db;
Spinner spinner;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_alertlist_all);

    BuildData();

    spinner = (Spinner) findViewById(R.id.spinner);
    spinner.setOnItemSelectedListener(this);
    spinnerData();

    recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    alertAllCustomAdapter = new AlertAllCustomeAdapter(this, peolesListAll);

    RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
    recyclerView.setLayoutManager(mLayoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setAdapter(alertAllCustomAdapter);
    alertAllCustomAdapter.notifyItemRangeChanged(0, alertAllCustomAdapter.getItemCount());

    private void spinnerData() {
    db = new DataBaseHelper(getApplicationContext());
    List<String> lables = db.getAllLabels();
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, lables);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // lables.set(0, "ALL");
    spinner.setAdapter(dataAdapter);

}
private List<People> BuildData() {
    db = new DataBaseHelper(getApplicationContext());

    try {
        db.createDataBase();
    } catch (IOException ioe) {
        throw new Error("Unable to create database");
    }

    if (db.open()) {
        peolesListAll = db.getAllPeople();

    }
    return peolesListAll;
}

 @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {


}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}

1 Answer 1

1

In the onItemSelected method you can retrieve the selected filter with position parameter from your spinner data (here the List lables). Then, re-populate your recylcer adadpter and call adapter.notifyDataSetChanged() to update the view like this :

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    String filter = (String) spinner.getAdapter().getItem(position);
    // update your peolesListAll according to the selected filter (with loop or anything else)
    alertAllCustomAdapter.setData(peolesListAll) // write setData(List<People> data)
    alertAllCustomAdapter.notifyDataSetChanged();
}
Sign up to request clarification or add additional context in comments.

1 Comment

any example@Francois L.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.