我想在文本字段为空时向用户显示所有建议,我从json响应中获取我的建议,当用户键入它出现在下拉列表中的单词但是当文本字段为空时它没有显示任何内容我甚至试过public static boolean isDateOdd(String date) {
DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
builder.parseCaseInsensitive();
builder.appendPattern("MMM dd yyyy");
DateTimeFormatter formatter = builder.toFormatter(Locale.ENGLISH);
LocalDate outputDate = LocalDate.parse(date, formatter);
return ((outputDate.getDayOfYear()%2!=0)?true:false);
}
}
,但Android Monitor说:尝试完成输入事件,但输入事件接收器已被处理。
这是我的代码:
showDropDown()
我首先从这些类中获取我的建议适配器 JSON Parser ,用于解析URL中的关键字。 getter setter 类。 建议适配器,用于在适配器中设置过滤的项目。 我的JSON回复:
public class MainActivity extends AppCompatActivity {
AutoCompleteTextView acTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
acTextView = (AutoCompleteTextView) findViewById(R.id.autoComplete);
acTextView.setAdapter(new SuggestionAdapter(this,acTextView.getText().toString()));
acTextView.setThreshold(0);
acTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
acTextView.showDropDown();
}
});
}
});
}
}
JSON Parser Class:
[{"lookupValueId":350,"lookupTypeId":33,"lookupValue":"Java"},{"lookupValueId":351,"lookupTypeId":33,"lookupValue":"C++"},{"lookupValueId":352,"lookupTypeId":33,"lookupValue":"Photoshop"},{"lookupValueId":353,"lookupTypeId":33,"lookupValue":"Java Script"}]
Getter setter类:
public class JsonParse {
public List<SuggestGetSet> getParseJsonWCF(String sName)
{
List<SuggestGetSet> ListData = new ArrayList<SuggestGetSet>();
try {
String temp = sName.replace(" ", "%20");
URL js = new URL("http://SomeUrl" + temp + "%22%7D%7D");
URLConnection jc = js.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(jc.getInputStream()));
String line = reader.readLine();
JSONArray jsonResponse = new JSONArray(line);
System.out.print("DATA: " + line);
for(int i = 0; i < jsonResponse.length(); i++){
JSONObject r = jsonResponse.getJSONObject(i);
ListData.add(new SuggestGetSet(r.getInt("lookupValueId"),r.getString("lookupValue")));
}
} catch (Exception e1) {
e1.printStackTrace();
}
return ListData;
}
}
最后是Adapter类:
public class SuggestGetSet {
String name;
static Integer id;
public SuggestGetSet(int id, String name){
this.setId(id);
this.setName(name);
}
public static Integer getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
我遵循了这个推荐:http://manishkpr.webheavens.com/android-autocompletetextview-example-json/