当我旋转屏幕时,我在Android执行的回调中有几个代码实例。由于这种“错误”行为,我总是测试屏幕旋转。但今天我想也许我做错了,或者这可能是一个应该报告给Android项目的bug。
最新的例子就是这个
我有一个AutoCompleteField。
FindReplaceAutoCompleteAdapter mAutoCompleteAdapter;
protected void onCreate(...){
mAutoCompleteAdapter = new FindReplaceAutoCompleteAdapter(this,
android.R.layout.simple_dropdown_item_1line);
mFindRule.setAdapter(mAutoCompleteAdapter);
}
我有适配器
public class FindReplaceAutoCompleteAdapter extends
ArrayAdapter<FindReplaceRuleContainer> {
private FindReplaceRuleFilter mFilter = null;
@Override
public Filter getFilter() {
if (mFilter == null)
mFilter = new FindReplaceRuleFilter();
return mFilter;
}
public FindReplaceAutoCompleteAdapter(Context context,
int textViewResourceId) {
super(context, textViewResourceId);
}
}
过滤器
public class FindReplaceRuleFilter extends Filter {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults fr = null;
if (constraint != null) {
List<FindReplaceRuleContainer> list = getFilterdValues(constraint
.toString());
if (list != null) {
fr = new FilterResults();
fr.values = list;
fr.count = list.size();
}
}
return fr;
}
private List<FindReplaceRuleContainer> getFilterdValues(String string) {
List<FindReplaceRuleContainer> lst = Sdbi
.loadFindReplaceRulesAutoComplete(FindReplaceList.this,
string);
return lst;
}
@Override
protected void publishResults(CharSequence constraint,
FilterResults results) {
/**
* Publish the result to the list activity so it looks pretty.
* Instead of a drop-down list
*/
mAutoCompleteAdapter.clear();
if( Adapter != null ){ //this is the fix I had to do because
//this code is called even though no filter action was launched
//It crashes because the Adapter is reloaded on an AsyncTask that
//start onResume() and may not be done by the time this code
//inexplicably resides to run
Adapter.clear();
if (results != null) {
...
}
Adapter.notifyDataSetChanged();
}
}
}
在onResume()之后旋转屏幕时调用publishResults()中的代码。 但是,当屏幕旋转时,甚至没有触摸自动完成字段。
在其他UI组件上可以看到此行为,但我无法记录其他实例。