とString[]
呼ばれる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[]
、1 つの文字列 (つまり"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ループを使用しようとしましたが、どこかで間違いを犯しています...