Enable Button when Spinner and EditText are not empty in Dialog - android

In my AlertDialog, I have a Spinner and an EditText. I am trying to disable the positive button of the dialog if
selected item at Spinner is "Select currency" ("Select currency" is the first item in my Array and Spinner is set to return String currencyName as "") or
EditText is empty.
In the code below, if I have input in EditText before selecting item in Spinner, the positive button remains disabled. I have no idea how to make these two work together.
Any help will be much appreciated. Thanks.
private void openDialog(){
LayoutInflater inflater = LayoutInflater.from(MainActivity.this);
View subView = inflater.inflate(R.layout.dialog_layout, null);
final EditText subEditTextExchangeRate = subView.findViewById(R.id.textInputExchangeRate);
final Spinner subSpinner = subView.findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.currency, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
subSpinner.setAdapter(adapter);
subSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if(parent.getItemAtPosition(position).equals("Select currency")){
currencyName = "";
}else {
currencyName = parent.getItemAtPosition(position).toString();
}
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(subView);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
exchangeRate = subEditTextExchangeRate.getText().toString();
st2 = exchangeRate;
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
}
});
final AlertDialog alertDialog = builder.create();
alertDialog.show();
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
subEditTextExchangeRate.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String exchangeRateInput = subEditTextExchangeRate.getText().toString();
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(!exchangeRateInput.isEmpty() && !currencyName.isEmpty());
}//This is the logic that I am looking for but the method is watching only EditText
#Override
public void afterTextChanged(Editable s) {
}
});
}

Please try below code with only one change, put below line in subSpinner.setOnItemSelectedListener and also please declare alertDialog globally.
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(!exchangeRateInput.isEmpty() && !currencyName.isEmpty());
Here is Your Code.
private void openDialog(){
LayoutInflater inflater = LayoutInflater.from(MainActivity.this);
View subView = inflater.inflate(R.layout.dialog_layout, null);
final EditText subEditTextExchangeRate = subView.findViewById(R.id.textInputExchangeRate);
final Spinner subSpinner = subView.findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.currency, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
subSpinner.setAdapter(adapter);
subSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if(parent.getItemAtPosition(position).equals("Select currency")){
currencyName = "";
}else {
currencyName = parent.getItemAtPosition(position).toString();
}
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(!exchangeRateInput.isEmpty() && !currencyName.isEmpty());
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(subView);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
exchangeRate = subEditTextExchangeRate.getText().toString();
st2 = exchangeRate;
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog = builder.create();
alertDialog.show();
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
subEditTextExchangeRate.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String exchangeRateInput = subEditTextExchangeRate.getText().toString();
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(!exchangeRateInput.isEmpty() && !currencyName.isEmpty());
}//This is the logic that I am looking for but the method is watching only EditText
#Override
public void afterTextChanged(Editable s) {
}
});
}

You should invoke button enable/disable logic Spinner.onItemSelected of your spinner. As of now you are only checking for logic in EditText.onTextChanged.
Declare your AlertDialog before setting listener on Spinner and EditText.
In Spinner.onItemSelected add your logic to enable or disable button.
In EditText.onTextChanged add your logic to enable or disable button.

you can make work your code if you change your code like,
Button button = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
button.setEnabled(false);
subEditTextExchangeRate.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(s.length>0 && !TextUtils.isEmpty(currencyName )){
button.setEnabled(true);
// your logic
}else{
button.setEnabled(false);
// your logic
}
#Override
public void afterTextChanged(Editable s) {
}
});
->this will do your work.

Related

Not able to add footer item in Recycler View dynamically

I am creating a list in which each list item has 3 widgets i.e. 2 EditText and 1 Spinner. And I have one add button to add a new view in the list.
I have created two views one is header view that has all 3 widgets with cross button and footer view that has all 3 widgets with the add button.
Initially, my footer view is shown. When I enter a value on all 3 widgets of that footer view I want to add those values into a model without clicking on it. Now it is working fine when I click on add button but I want to add it without clicking on add button when all values are filled.
Please help.
if (holder instanceof FooterViewHolder) {
final FooterViewHolder footerHolder = (FooterViewHolder) holder;
unitlist = new ArrayList<>();
// unitlist.add(0, "Select");
unitlist.add(0, "unit");
unitlist.add(1, "gram");
unitlist.add(2, "litre");
spinnerAdapter = new ArrayAdapter<String>(activity, R.layout.spinner, unitlist) {
#Override
public boolean isEnabled(int position) {
return true;
}
};
spinnerAdapter.setDropDownViewResource(R.layout.spinner_dropdown);
((FooterViewHolder) holder).spinner.setAdapter(spinnerAdapter);
//spinner select type of life stage
((FooterViewHolder) holder).spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
((TextView) parent.getChildAt(0)).setTextColor(Color.BLACK);
unitName = parent.getItemAtPosition(position).toString();
selected_item = ((FooterViewHolder) holder).spinner.getSelectedItemPosition();
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
//Another interface callback
}
});
footerHolder.ibAddMore.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (footerHolder.etIngredientName.getText().length() == 0) {
Toast.makeText(activity, R.string.pls_enter_ingredient_name, Toast.LENGTH_SHORT).show();
} else if (((FooterViewHolder) holder).spinner.getSelectedItem().toString().trim().equals("Select")) {
Toast.makeText(activity, R.string.pls_enter_unit_conversion_value, Toast.LENGTH_SHORT).show();
} else if (footerHolder.etAmount.getText().length() == 0) {
Toast.makeText(activity, R.string.pls_enter_qty, Toast.LENGTH_SHORT).show();
} else {
ArrayList<ModelInventory> modelInventoryArrayList = new ArrayList<>();
modelInventoryArrayList = databaseHelper.getInventoryByName(footerHolder.etIngredientName.getText().toString());
Log.e("TAG", "checkUnit:d "+footerHolder.etAmount.getText().toString() + "))" +modelInventoryArrayList.size());
if(modelInventoryArrayList.size() >0){
for(ModelInventory modelInventory : modelInventoryArrayList){
Log.e("TAG", "checkUnit: "+modelInventory.getItemQty() +")))"+unitName );
if(modelInventory.getItemQty().equals(unitName)){
fragmentNewRecipe.addView(footerHolder.etAmount.getText().toString(), position, footerHolder.etIngredientName.getText().toString(), unitName);
}else{
Toast.makeText(activity,R.string.measurement_diff,Toast.LENGTH_SHORT).show();
}
}
}else{
fragmentNewRecipe.addView(footerHolder.etAmount.getText().toString(), position, footerHolder.etIngredientName.getText().toString(), unitName);
}
}
}
});
}
View:
Try adding listeners to each edit text and whenever an input change detected, Check whether all inputs are non empty, and add to your list
footerHolder.etAmount.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
if (s.toString() != ""){
if (footerHolder.etIngredientName.getText().length() != 0) {
//Add item to your list
}
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {}
});
footerHolder.etIngredientName.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
if (s.toString() != ""){
if (footerHolder.etAmount.getText().length() != 0) {
//Add item to your list
}
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {}
});

Android: Search on ListView

I need a quick solution for my problem. I have a ListView, and I want to search from that. Im a kind a starter with the filtering and the adapters, so this is my Fragment's code:
View v;
DB mydb;
ListView listView;
final ArrayList<String> thelist = new ArrayList<>();
final ArrayList<String> deletelist= new ArrayList<>();
boolean torles=false;
String delete; int id;
private ListAdapter listadapter;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
v = inflater.inflate(R.layout.fragment_numberone, container, false);
listView = (ListView) v.findViewById(R.id.list);
mydb = new DB(getActivity());
loadlist();
EditText filter = (EditText)v.findViewById(R.id.filter);
filter.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
getActivity().listadapter.getFilter().filter(s);
//Here is the problem
}
#Override
public void afterTextChanged(Editable s) {
}
});
listView.setOnItemClickListener(
new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
id = Integer.parseInt(deletelist.get(i));
delete=thelist.get(i);
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
alert.setTitle("Title");
alert.setMessage("Message");
alert.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
mydb.grade_delete(id);
listView.removeAllViewsInLayout();
thelist.removeAll(thelist);
deletelist.removeAll(deletelist);
loadlist();
}
});
alert.setNegativeButton("No", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
}
});
alert.create().show();
}
}
);
return v;
}
public void loadlist() {
Cursor data = mydb.Jegynevlekerdezes();
if (data.getCount() == 0) {
} else {
while (data.moveToNext()) {
thelist.add(data.getString(0)+": "+data.getString(1));
deletelist.add(data.getString(2));
listadapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, android.R.id.text1, thelist);
listView.setAdapter(listadapter);
}
}
}
}
My problem is with this:
getActivity().listadapter.getFilter().filter(s);
The listadapter is wrong, it's show as red. Like I sad, I'm new with the adapter and the searching.

Getting item position in AutoCompleteTextView addTextChangeListener method

I have Autocomplete textviews in my custom adapter. when i write something in onTextChange listener, i want to get item position. I it gives all items positions. Please help me regarding this issue. Thanks!
autoCompleteTextView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
String selection = (String)parent.getItemAtPosition(position);
//TODO Do something with the selected text
}
});
This is how you can get position of Item you typed in AutoCompleteTextView. But you have to add the full name of item like "apple" or "apples" then this code will give you the position of that particular item. But its very expensive process if you have lots of items in your list.
public class Test extends AppCompatActivity {
private AutoCompleteTextView autoCompleteTextView;
private List<String> list;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chintan_test);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
list = new ArrayList<>();
list.add("Apple");
list.add("Apples");
list.add("Banana");
list.add("Aunt");
list.add("Orange");
autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
autoCompleteTextView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list));
autoCompleteTextView.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
for (String string : list)
if (string.toLowerCase().equals(s.toString().toLowerCase())) {
int pos = list.indexOf(string);
Toast.makeText(Test.this, "" + pos, Toast.LENGTH_SHORT).show();
}
}
#Override
public void afterTextChanged(Editable s) {
}
});
}
}
Let me know if this code helps you.
Use textwatcher, implement it in activity class.
#Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
hi can you please check there is some issue
AutoCompleteTextView tv = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
final ArrayList<Student> list = new ArrayList<MainActivity.Student>();
list.add(new Student("abc"));
list.add(new Student("abc"));
ArrayAdapter<Student> adapter = new ArrayAdapter<MainActivity.Student>(
this, android.R.layout.simple_dropdown_item_1line, list);
tv.setAdapter(adapter);
tv.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Student selected = (Student) arg0.getAdapter().getItem(arg2);
Toast.makeText(MainActivity.this,
"Clicked " + arg2 + " name: " + selected.name,
Toast.LENGTH_SHORT).show();
}
});
for more checking you can go from here...
you can use addTextChangedListener for this purpose
yourAutoCompleteTextView.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void afterTextChanged(Editable s) {
} });

Update spinner in view and change its selected item

I'm having trouble with quite a simple layout in Android. Basically, I have a spinner that contains several items from a sqlite database. I also have some EditText fields that receive and display the information from the selected item. What I to do now is to implement a button that allows the user to add a new entry and change its data - all in the same view (the EditText fields are already programmated to do that). Here's my code (what I tried to do is to update the database with default data from the new item and redraw the class, but I can't get to set the spinner to the new position). Do you guys have any idea on how I can do that?
public class Activity_MaterialTab extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_materialtab);
//Opens database
final SQLiteDatabase Estrutura = openOrCreateDatabase("Estutura.db", Context.MODE_PRIVATE, null);
final Cursor cursor = Estrutura.rawQuery("SELECT * FROM MATERIAIS ORDER BY [_id] ASC", null);
final Spinner spnMaterial = (Spinner) findViewById(R.id.mat_spn_material);
final EditText dVol = (EditText) findViewById(R.id.mat_frm_densidade);
final EditText modE = (EditText) findViewById(R.id.mat_frm_elasticidade);
final EditText nome = (EditText) findViewById(R.id.mat_frm_nome);
final ImageButton addMaterial = (ImageButton) findViewById(R.id.mat_btm_add);
final ImageButton excMaterial = (ImageButton) findViewById(R.id.mat_btm_exc);
final Bundle sis = savedInstanceState;
//Spinner
String from[] = {"_id","nome","modE","dVol"};
int to[] = {R.id.txvid,R.id.txvnome,R.id.txvmodE,R.id.txvdVol};
SimpleCursorAdapter ad = new SimpleCursorAdapter(getBaseContext(), R.layout.sp_material, cursor, from, to, 0);
spnMaterial.setAdapter(ad);
try {
spnMaterial.setSelection(sis.getInt("pos"));
} catch (Exception e) {}
//Updates Edittext fields
modE.setText(String.valueOf(cursor.getDouble(2)));
dVol.setText(String.valueOf(cursor.getDouble(3)));
spnMaterial.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view,int position, long id) {
Cursor cursor2 = Estrutura.rawQuery("SELECT * FROM MATERIAIS ORDER BY [_id] ASC", null);
cursor2.moveToPosition(cursor.getPosition());
nome.setText(String.valueOf(cursor2.getDouble(1)));
modE.setText(String.valueOf(cursor2.getDouble(2)));
dVol.setText(String.valueOf(cursor2.getDouble(3)));
cursor.moveToPosition(position);
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
modE.addTextChangedListener(new TextWatcher()
{
#Override
public void beforeTextChanged(CharSequence s, int start, int count,int after) {}
#Override
public void onTextChanged(CharSequence s, int start, int before,int count) {}
#Override
public void afterTextChanged(Editable s) {
if (modE.length() != 0) {
String sql = "UPDATE MATERIAIS SET modE="+modE.getText().toString()+" WHERE [_id]="+String.valueOf(cursor.getInt(0));
Estrutura.execSQL(sql);
}
}
});
dVol.addTextChangedListener(new TextWatcher()
{
#Override
public void beforeTextChanged(CharSequence s, int start, int count,int after) {}
#Override
public void onTextChanged(CharSequence s, int start, int before,int count) {}
#Override
public void afterTextChanged(Editable s) {
if (dVol.length() != 0) {
String sql = "UPDATE MATERIAIS SET dVol="+dVol.getText().toString()+" WHERE [_id]="+String.valueOf(cursor.getInt(0));
Estrutura.execSQL(sql);
}
}
});
addMaterial.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v) {
String sql = "INSERT INTO MATERIAIS(nome,modE,dVol) VALUES('Nome',0,0)";
Estrutura.execSQL(sql);
sis.putInt("pos", cursor.getPosition());
onCreate(sis);
spnMaterial.setSelection(3);
}
});
}
}

Restore listview in dialog after search

I am have a small problem in my custom dialog.
When the user search for an item in the listview, the list shows the right items, but if the user for example wants to search again, the listview shows the results from the previous search.
The problem:
How do I restore the listview after the first search?
My activity with the custom dialog
edit.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
showDialog();
}
});
}
}
private void showDialog() {
dialog = new Dialog(this);
View view = getLayoutInflater().inflate(R.layout.material_list, null);
searchList = (ListView) view.findViewById(R.id.searchList);
dialog.setTitle("Välj ny artikel");
final MaterialAdapter adapter = new MaterialAdapter(
InformationActivity.this, materialList);
dialog.setContentView(view);
searchList.setAdapter(adapter);
searchList.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
Materials itemMat = materialList.get(position);
resultProduct = itemMat.materialName;
resultProductNo = itemMat.materialNo;
result = resultProduct + " " + resultProductNo;
Toast.makeText(getApplicationContext(), result,
Toast.LENGTH_SHORT).show();
}
});
search = (EditText) dialog.findViewById(R.id.search);
search.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
resultText = search.getText().toString()
.toLowerCase(Locale.getDefault());
adapter.filter(resultText);
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
#Override
public void afterTextChanged(Editable s) {
}
});
cancel = (Button) dialog.findViewById(R.id.btnCancel);
cancel.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
ok = (Button) dialog.findViewById(R.id.btnOK);
ok.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
product.setText(resultProduct);
productNo.setText(resultProductNo);
dialog.dismiss();
}
});
dialog.show();
}
}
My adapter
public class MaterialAdapter extends BaseAdapter {
LayoutInflater inflater;
Context context;
List<Materials> searchItemList = null;
ArrayList<Materials> materialList = new ArrayList<Materials>();
public MaterialAdapter(Context context, List<Materials> searchItemList) {
this.context = context;
inflater = LayoutInflater.from(context);
this.searchItemList = searchItemList;
this.materialList = new ArrayList<Materials>();
this.materialList.addAll(searchItemList);
}
#Override
public int getCount() {
return searchItemList.size();
}
#Override
public Object getItem(int position) {
return searchItemList.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder viewHolder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.d, null);
viewHolder = new ViewHolder();
viewHolder.tvMaterialName = (TextView) convertView
.findViewById(R.id.tvMaterialName);
viewHolder.tvMaterialNo = (TextView) convertView
.findViewById(R.id.tvMaterialNo);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.tvMaterialName.setText((searchItemList.get(position))
.getMaterialName());
viewHolder.tvMaterialNo.setText((searchItemList.get(position))
.getMaterialNo());
return convertView;
}
public class ViewHolder {
TextView tvMaterialName;
TextView tvMaterialNo;
}
public void filter(String charText) {
charText = charText.toLowerCase(Locale.getDefault());
searchItemList.clear();
if (charText.length() == 0) {
searchItemList.addAll(materialList);
} else {
for (Materials wp : materialList) {
if (wp.getMaterialName().toLowerCase(Locale.getDefault())
.startsWith(charText)) {
searchItemList.add(wp);
}
}
}
notifyDataSetChanged();
}
}
Thanks for the help :)
Try to change search.getText() to s.toString()
public void onTextChanged(CharSequence s, int start, int before,
int count) {
resultText = search.getText().toString()
.toLowerCase(Locale.getDefault());
adapter.filter(resultText);
}
to
public void onTextChanged(CharSequence s, int start, int before, int count) {
resultText = s.toString().toLowerCase(Locale.getDefault());
adapter.filter(resultText);
}
A secondary thing, make materialList = searchItemList; And searchItemList empty which will be filled with search items (first run will be same elements of materialList.)
P.S Your adapter should implement Filterable in this case (implements Filterable)
#Override
public void afterTextChanged(Editable s) {
resultText = search.getText().toString()
.toLowerCase(Locale.getDefault());
adapter.filter(resultText);
}
Try this and check whether it helps

Categories

Resources