我有一个String[]
call lv_arr
,我的活动如下所示:
它包含一个EditText
和以下,我lv_arr[]
使用此代码显示一个以上:
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);
当前lv_arr[]
仅包含一个字符串(即"Notes"
),并且每当用户添加一个字符串时,它都会被更新。我想添加TextWatcher
我的EditText
,所以我尝试了以下方法:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/addLabelText"
android:hint="Add Label">
<requestFocus/>
</EditText>
和:
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) {
}
};
我想要一个最终输出,每当用户在其中键入任何内容时,EditText
我的列表中的重要值都应该显示在它的下方。当它EditText
进入空白状态时,下面的列表应显示所有元素。否则只有匹配的值应该是可见的。
我尝试使用 for 循环,以便获得匹配的值,但我在某处犯了错误......