我想搜索城市。我从服务器数据库获取城市的名称,我在listview.i上的Android手机上获得这个城市名称也使用搜索过滤器。在此代码中,我已经将arraylist转换为array.It没有从arraylist转换为postexecute中的数组。我可以将arraylist转换为数组??? 这是我的代码,我收到此错误:android.widget.ArrayAdapter.createViewfromresources中的java.lang.nullpointerexception 提前谢谢你
protected void onPostExecute(String file_url)
{
runOnUiThread(new Runnable()
{
public void run()
{
for(int j=1;j<10;j++)
{
ListView lv = getListView();
String[] namesArr = new String[weatherlist.size()];
namesArr[j]=weatherlist.get(j).get(TAG_STATION);
Log.d("weather",namesArr[j]);
adapter = new ArrayAdapter<String>(Search.this, R.layout.list_item1, R.id.station_name, namesArr);
// updating list view
lv.setAdapter(adapter);
inputSearch.addTextChangedListener(new TextWatcher()
{
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3)
{
// When user changed the Text
Search.this.adapter.getFilter().filter(cs);
}
});
}
答案 0 :(得分:0)
试试这个;
protected void onPostExecute(String file_url)
{
pDialog.dismiss();
runOnUiThread(new Runnable()
{
public void run()
{
String[] namesArr = new String[weatherlist.size()];
for(int i = 0 ; i < weatherlist.size() < i++){
namesArr[i] = weatherlist.get(i).get("yourstringkey");
}
adapter = new ArrayAdapter<String>(Search.this, R.layout.list_item1, R.id.station_name, namesArr);
// updating list view
lv.setAdapter(adapter);
inputSearch.addTextChangedListener(new TextWatcher()
{
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3)
{
// When user changed the Text
Search.this.adapter.getFilter().filter(cs);
}
});
}
});
}
}
}