0
我创建了一个简单的适配器,以便自动完成我的自动完成文本视图,并且我想在用户单击自动完成文本时隐藏键盘。Android - 在SimpleAdapter上隐藏键盘
我已经创建了一个隐藏de键盘的函数,但是我在SimpleAdapter上使用它有一些问题,我只需要获取当前活动来调用函数。
隐藏键盘功能在这里:
public static void hideSoftKeyboard(Activity activity) {
InputMethodManager inputMethodManager = (InputMethodManager) activity
.getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus()
.getWindowToken(), 0);
}
SimpleAdapter代码:
public class ACAdapter extends SimpleAdapter {
Context context;
public ACAdapter(Context context, List<? extends Map<String, ?>> data,
int resource, String[] from, int[] to) {
super(context, data, resource, from, to);
// TODO Auto-generated constructor stub
}
public View getView(final int position, final View convertView,
final ViewGroup parent) {
View v = super.getView(position, convertView, parent);
final String id = (String) ((Map) getItem(position))
.get(EventsFragment.ITEM_SECTIONID);
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
GetSpots task = new GetSpots();
task.execute(id);
EventsFragment.refresh = false;
EventsFragment.loading_bg.setVisibility(View.VISIBLE);
hideSoftKeyboard(context.getActivity());
}
});
return v;
}
}
所以,我试图用 “context.getActivity”,但没有工作,我收到这样的警告:
The method getActivity() is undefined for the type Context
有没有办法做我想要的?
没有工作“的方法hideSoftKeyboard(活动)是未定义的类型新View.OnClickListener(){}” –
是现在工作很好,谢谢 –
@RúbenDias提醒一下,要小心'activity.getCurrentFocus()'因为这可能会返回'null' – user2234894