我正在使用过滤器类中的toast。这是它的代码
public void filter(String charText) {
charText = charText.toLowerCase(Locale.getDefault());
expressionlist.clear();
if (charText.length() == 0) {
expressionlist.addAll(arraylist);
} else {
for (Expression wp : arraylist) {
if (wp.getWord().toLowerCase(Locale.getDefault())
.contains(charText)) {
expressionlist.add(wp);
}
}
if(expressionlist.size() == 0){
Toast toast = Toast.makeText(this, "No match found", Toast.LENGTH_LONG);
toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
toast.show();
// add all items of expressionlist
expressionlist.addAll(arraylist);
}
}
notifyDataSetChanged();
}
}
我收到错误Toast类型中的方法makeText(Context, CharSequence, int)
不适用于参数(ListViewAdapter, String, int)
我该如何解决这个问题?
答案 0 :(得分:2)
您应该引用上下文,即getApplicationContext()
或传递ListViewAdapter的上下文。
上下文可以是Activity
或Fragment
Toast toast = Toast.makeText(context, "No match found", Toast.LENGTH_LONG);