我想一個過濾器添加到我的適配器類(它擴展了BaseAdapter)。設置過濾器適配器事業強制關閉應用
每一件事情正在啓動應用程序後,工作很細,但被重新創建活動時(通過屏幕旋轉或調用的onCreate)應用程序停止工作並提出了強制關閉錯誤
當我刪除此行有是重新創建活動
MainActivity.this.adapter.getFilter().filter(cs);
沒有問題,但調試器顯示錯誤是
super.onCreate(savedInstanceState);
這裏是我的主要活動onCrea TE功能:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new Updator().execute();//Updator is a AsyncTask to update adapter
EditText inputSearch = (EditText) findViewById(R.id.editText1);
inputSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int start, int before, int count)
{
MainActivity.this.adapter.getFilter().filter(cs);//after screen rotation - application stops working when executing this line
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
});
}
,這是自定義適配器類我的濾波方法:
private class CustomListFilter extends Filter
{
@Override
protected FilterResults performFiltering(CharSequence constraint)
{
FilterResults results = new FilterResults();
String prefix = constraint.toString().toLowerCase();
if (prefix == null || prefix.length() == 0)
{
results.values = original;
results.count = original.size();
}
else
{
final ArrayList<App> nlist = new ArrayList<App>();
int count = original.size();
App pkmn;
String value;
for (int i=0; i<count; i++)
{
pkmn = original.get(i);
value = pkmn.getName().toLowerCase();
if (value.contains(prefix))
{
nlist.add(pkmn);
}
}
results.values = nlist;
results.count = nlist.size();
}
return results;
}
@SuppressWarnings("unchecked")
@Override
protected void publishResults(CharSequence constraint, FilterResults results)
{
mApps = (ArrayList<App>)results.values;
if (mApps.size() > 0)
notifyDataSetChanged();
else
notifyDataSetInvalidated();
}
}
請從logcat的 –
添加異常的堆棧跟蹤@GilMoshayof我不是那麼熟悉Eclipse,其中堆棧跟蹤? – Arashdn
@GilMoshayof請張貼logcat中,得到的logcat看到這個帖子http://stackoverflow.com/questions/11608718/how-to-copy-logcat-output-to-clipboard –