TextWatcher crash when get edittext

By | October 30, 2018
Questions:

After I type, it gives me the message: your app isn`t responding.
do you want to close it?
WAIT OK

I think because of the edt_search.gettext().tostring() inside the setData()

 private void setupViews() {
edt_search = findViewById(R.id.edt_search);
progress = findViewById(R.id.progress);
progress.hide();

edt_search.addTextChangedListener(new TextWatcher() {
  @Override
  public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

  }

  @Override
  public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

  }

  @Override
  public void afterTextChanged(Editable editable) {
    if (editable.length() != 0) {
      setData();
    }
  }
});
}



private void setData() {
AndroidNetworking.post("uri")
  .addBodyParameter("word", edt_search.getText().toString())
  .build()
  .getAsObjectList(Search.class, new ParsedRequestListener<List<Search>>() {
    @Override
    public void onResponse(List<Search> searches) {
      for (Search search : searches) {
        searchList.add(search);
        adapter.notifyDataSetChanged();
      }
      loading(false);
    }

    @Override
    public void onError(ANError anError) {
      Log.e("android-networking", "error: " + anError.getLocalizedMessage());
    }
  });
}
Answers:

Leave a Reply

Your email address will not be published. Required fields are marked *