Friday, 24 May 2019

Perform search in RecyclerView android

In MainActivity :- 


stcCityNAme is string array
private void filterData(String filterText) {
    List<String> filteList = new ArrayList<>();
    for (String s:stcCityNAme) {
        if(s.toLowerCase().startsWith(filterText))
        filteList.add(s);
    }
    if(filteList.size() == 0) {
        Toast.makeText(getApplicationContext(),"No Data Found",Toast.LENGTH_SHORT).show();
    }
    adapter.filter(filteList);
}



in Adapter :-
public void filter(List<String> filteList) {
    this.list = filteList;
    notifyDataSetChanged();
}

Xml:-



Message Passing  from one Activity to Another Activity :-

ClassA:-
Intent intent = new Intent(ClassB.this,ClassC.class);
intent.putExtra("messageB","Message form ClassB....:::");
startActivityForResult(intent,123);

@Overrideprotected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Log.d("supriya",resultCode+"");
    if(requestCode == 123) {
        messageB.setText(data.getStringExtra("messageC"));
    }
}

ClassB:-
// Get the transferred data from source activity.Intent intent = getIntent();
messageC.setText(intent.getStringExtra("messageB"));

Intent intent = new Intent();
intent.putExtra("messageC", "Message back from C");
setResult(RESULT_OK, intent);
finish();

No comments:

Post a Comment