今天我有一个具体的问题,我在谷歌搜索,但找不到任何可以帮助的答案。AutoCompleteTextView OnItemClickListener不起作用
我的活动有一个AsyncTask从数据库加载一些字符串并在autocompletetextview中显示它们。我使用HttpUrlConnection获取字符串,然后使用json-simple库解析它们,然后在autocompletetextview中显示它们。下面是ACTV)全码这是onPostExecute(:
ArrayList<Object> result = new ArrayList<>();
for (Shift_OneTime sot : shifts) {
result.add(sot.getName() + " " + sot.getDay() + " " + sot.getMonth() + " " + sot.getYear());
}
for (Employee e : emps) {
result.add(e.toString());
}
acs = (AutoCompleteTextView) findViewById(R.id.autocompletesearch);
ArrayAdapter<Object> adapter = new ArrayAdapter<>(MainScreen.this, android.R.layout.simple_list_item_1, result);
acs.setAdapter(adapter);
acs.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
acs.setText("");
acs.clearFocus();
Object o = adapterView.getItemAtPosition(i);
if (o instanceof Employee) {
Intent n = new Intent(MainScreen.this, EmployeeDetailsActivity.class);
n.putExtra("employeeid", ((Employee) o).getId());
startActivity(n);
} else if (o instanceof Shift_OneTime) {
Intent n = new Intent(MainScreen.this, ShiftDetailsActivity.class);
n.putExtra("shiftid", ((Shift_OneTime) o).getId());
startActivity(n);
}
}
});
即时得到这一堆警告:当我点击字符串输入一些内容后显示出来
W/IInputConnectionWrapper: getSelectedText on inactive InputConnection
W/IInputConnectionWrapper: requestCursorAnchorInfo on inactive InputConnection
W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
这些错误出现autocompletetextview。现在我的观察并不确定,但是上次它正在使用旧的DefaultHTTPClient或者现在不赞成使用的东西。这就是我改为HttpURLConnection的原因。在更改之后,我还将ACTV移动到了AsyncTask中,就像Im从我的php webservice中读取字符串一样,并且我还添加了ActionBarDrawerToggle并覆盖其方法,以便在打开导航抽屉时隐藏软键盘。
我试图删除扩展切换,我也试图把onItemClickListener()放回到AsyncTask之外,但它没有帮助。我不能真正回到现在已弃用的HTTP客户端,所以我想知道是否有人有任何想法...非常感谢
不,setOnClickListener会在您点击ACTV时作出反应。这不是我想 –
你错过了,而且只是为了确保你得到正确的东西 – Catluc
我以前在那里,没有任何ifs被处理,但那还是 –