1
我在onTextChanged()函數中的adapter.getFilter()。filter(s)處得到一個錯誤。我正在關注這個 - How to dynamically update a ListView on Android - 在對話框中創建一個可過濾列表。任何人都可以請幫我改正這段代碼嗎?
public class CustomizeDialog extends Dialog implements OnClickListener {
private final String[] cityList = {"Seattle", "London"}; private EditText filterText = null;
ArrayAdapter<String> adapter = null;
public CustomizeDialog(Context context) {
super(context);
/** Design the dialog in main.xml file */
setContentView(R.layout.main);
filterText = (EditText) findViewById(R.id.EditBox);
filterText.addTextChangedListener(filterTextWatcher);
this.setTitle("Select");
list = (ListView) findViewById(R.id.List);
list.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, cityList));
}
@Override
public void onClick(View v) {
/** When OK Button is clicked, dismiss the dialog */
}
private TextWatcher filterTextWatcher = new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
adapter.getFilter().filter(s);
}
};
}
非常感謝。對不起,問這樣一個愚蠢的問題,我是新來的android。再次感謝 – 2010-11-01 05:35:16
這個社區全是關於學習,不需要道歉,樂於幫助。 – 2010-11-01 05:36:55
如何摧毀物體?我的意思是我在哪裏調用filterText.removeTextChangedListener(filterTextWatcher); ? – 2010-11-01 06:22:35