简体   繁体   English

ListView OnItemClickListener不适用于LazyAdapter ListView

[英]ListView OnItemClickListener doesn't work with LazyAdapter ListView

I have implemented a Custom ListView using LazyAdapter to display thumbnail images. 我已经实现了使用LazyAdapter来显示缩略图的Custom ListView。 Finally after I got this LazyAdapter working, the OnItemClickListener doesn't display the data and simply returns the empty strings. 最后,在我使LazyAdapter工作之后,OnItemClickListener不会显示数据,而只是返回空字符串。 The code is working fine if I remove the Custom LazyAdapter class for the ListView. 如果删除ListView的Custom LazyAdapter类,则代码工作正常。

    class LoadAllDirectories extends AsyncTask<String, String, String> {

        protected String doInBackground(String... args) {

            UserFunctions fn = new UserFunctions();
            String id = fn.getID(getApplicationContext());

            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("id", id));

            JSONObject json = 
            jParser.makeHttpRequest(url_all_directories, "GET", params);

            Log.d("All Directories: ", json.toString());

            try {

                int success = json.getInt(TAG_SUCCESS);

                if (success == 1) {

                    directories = json.getJSONArray(TAG_DIRECTORIES);

                    for (int i = 0; i < directories.length(); i++) {
                        JSONObject c = directories.getJSONObject(i);

                        String eid = c.getString(TAG_ID);
                        String name = c.getString(TAG_NAME);                        
                        String image = c.getString(TAG_IMG);

                        HashMap<String, String> map = 
                        new HashMap<String, String>();

                        map.put(TAG_ID, eid);
                        map.put(TAG_NAME, name);                        
                        map.put(TAG_IMG, image);

                        directoryList.add(map);
                    }

                } else {

                    Intent i = new Intent(getApplicationContext(),
                            DirectoryActivity.class);

                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(i);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }

        protected void onPostExecute(String file_url) {

            runOnUiThread(new Runnable() {
                public void run() {

                    ListAdapter adapter = new LazyAdapter(
                    DirectoryAllActivity.this, directoryList);                  
                    setListAdapter(adapter);
                }
            });

        }

    }

}

ErrorLog 错误日志

update: part of the duplicated Log was deleted. 更新:重复日志的一部分已删除。

11-19 14:17:12.612: W/System.err(16343): java.net.MalformedURLException: Protocol not found: null
11-19 14:17:12.612: W/System.err(16343):    at java.net.URL.<init>(URL.java:178)
11-19 14:17:12.612: W/System.err(16343):    at java.net.URL.<init>(URL.java:127)
11-19 14:17:12.612: W/System.err(16343):    at com.app.android.library.ImageLoader.getBitmap(ImageLoader.java:70)
11-19 14:17:12.612: W/System.err(16343):    at com.app.android.library.ImageLoader.access$0(ImageLoader.java:58)
11-19 14:17:12.612: W/System.err(16343):    at com.app.android.library.ImageLoader$PhotosLoader.run(ImageLoader.java:135)
11-19 14:17:12.612: W/System.err(16343):    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
11-19 14:17:12.622: W/System.err(16343):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
11-19 14:17:12.622: W/System.err(16343):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
11-19 14:17:12.622: W/System.err(16343):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
11-19 14:17:12.622: W/System.err(16343):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
11-19 14:17:12.622: W/System.err(16343):    at java.lang.Thread.run(Thread.java:856)
11-19 14:17:12.653: D/memalloc(16343): ion: Mapped buffer base:0x5e951000 size:3768320 offset:0 fd:55
Caused By: java.net.MalformedURLException

You need to use a real URL, not this: 您需要使用真实的URL,而不是这样:

private static String url_all_directories = "a_web_url";

You can start with the tutorial's suggested URL: http://api.androidhive.info/music/music.xml 您可以从教程的建议URL开始: http : //api.androidhive.info/music/music.xml


Hey! 嘿! You sneakily changed your LogCat. 您偷偷地更改了LogCat。

Anyway, now the problem is an image URL: 无论如何,现在的问题是图像URL:

at com.app.android.library.ImageLoader.getBitmap(ImageLoader.java:70) 

Check the data at "a_web_url", which is apparently on a server of yours... 检查“ a_web_url”上的数据,该数据显然在您的服务器上...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM