I have a String[]
called lv_arr
, and my activity looks like this:
It contains a EditText
and below that I am displaying a above lv_arr[]
using this code:
listView = (ListView) findViewById(R.id.listview);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_single_choice,lv_arr);
listView.setAdapter(adapter);
Currently lv_arr[]
contains only one string (i.e "Notes"
), and whenever the user adds a string it will be updated. I want to add TextWatcher
on my EditText
, so I tried the following:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/addLabelText"
android:hint="Add Label">
<requestFocus/>
</EditText>
With:
addLabelText = (EditText) findViewById(R.id.addLabelText);
addLabelText.addTextChangedListener(listWatcher);
}
private final TextWatcher listWatcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int i, int i1, int i2) {
System.out.println(s);
}
@Override
public void onTextChanged(CharSequence s, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
}
};
I want a final output which, whenever user types anything in that EditText
, the significant values from my list should be displayed below it. When that EditText
is goes to a blank state, the below list should display all elements. Otherwise only matching values should be visible.
I tried using a for loop so that I can get matching values, but I am making a mistake somewhere...