【发布时间】:2014-07-30 08:55:15
【问题描述】:
我正在尝试在我的 android 应用程序中创建一个搜索字段。我需要将 ArrayList 转换为 String 数组以显示值和搜索。我有:
inputSearch = (EditText) findViewById (R.id.searchText);
myAdapter = new ArrayAdapter<String>(this, R.layout.plates, R.id.title, mPlatesList);
lv.setAdapter(myAdapter);
inputSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
Lista.this.myAdapter.getFilter().filter(cs);
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
}
@Override
public void afterTextChanged(Editable arg0) {
}
});
和
mPlatesList = new ArrayList<HashMap<String, String>>();
mPlates = json.getJSONArray(TAG_POSTS);
// looping through all posts according to the json object returned
for (int i = 0; i < mPlates.length(); i++) {
JSONObject c = mPlates.getJSONObject(i);
// gets the content of each tag
String targa = c.getString(TAG_TARGA);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_TARGA, targa);
// adding HashList to ArrayList
mPlatesList.add(map);
我收到上述错误。我是 android 新手,所以我不知道如何从一种类型转换为另一种类型。
Error:(32, 38) error: no suitable constructor found for ArrayAdapter(Lista,int,int,ArrayList<HashMap<String,String>>)
constructor ArrayAdapter.ArrayAdapter(Context,int,int,String[]) is not applicable
(argument mismatch; ArrayList<HashMap<String,String>> cannot be converted to String[])
constructor ArrayAdapter.ArrayAdapter(Context,int,int,List<String>) is not applicable
(argument mismatch; ArrayList<HashMap<String,String>> cannot be converted to List<String>)
【问题讨论】:
-
如果您需要 ArrayList 和 HashMap,那么您已经为您的列表制作了自定义适配器。
-
在这里查看我的答案:stackoverflow.com/questions/24954285/…
-
你能指定你想要的字符串数组吗?我的意思是 ArrayList 是 hashmap。你想要键或值的字符串数组?
-
那么您究竟想从该数据结构中显示什么?
-
@Preethi Rao 我想要价值观。执行搜索
标签: java android arraylist android-studio