小编Chr*_*ard的帖子

Android adapter.notifyDataSetChanged()不起作用?

我正在编写一个应用程序,需要从用户那里获取输入,将其传递给服务器,该服务器返回一个JSON字符串,然后在ListView中显示其解析的内容.我正在通过扩展AsyncTask来实现这一目标:

//stripped down version
public class main extends ListActivity {

ArrayList<String> listItems = new ArrayList<String>();
ArrayAdapter<String> adapter;
final EditText input = (EditText)findViewById(R.id.input);


input.addTextChangedListener(new TextWatcher() {    
    public void onTextChanged(CharSequence s, int start, int before, int count) {   
            if(!input.getText().toString().equals("")) {
            new GetDataTask().execute(input.getText().toString());
        }

    }   
});

private class GetDataTask extends AsyncTask<String, Void, ArrayList<String>> {
        protected ArrayList<String> doInBackground(String... query) {

        URL url = new URL("http://myserversaddressgoeshere.com/search/thequerygoeshere");
        URLConnection conn = url.openConnection();
        BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            ArrayList<String> items = new ArrayList<String>();
        //the code that parses …
Run Code Online (Sandbox Code Playgroud)

android

10
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1