gpt4 book ai didi

java - ListView OnItemClickListener 不适用于 LazyAdapter ListView

转载 作者:行者123 更新时间:2023-12-01 15:02:19 24 4
gpt4 key购买 nike

我已经使用 LazyAdapter 实现了自定义 ListView 来显示缩略图。最后,在我让这个 LazyAdapter 工作后,OnItemClickListener 不显示数据,只是返回空字符串。如果我删除 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);
}
});

}

}

}

错误日志

更新:删除了部分重复日志。

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

您需要使用真实的 URL,而不是这个:

private static String url_all_directories = "a_web_url";

您可以从本教程建议的 URL 开始:http://api.androidhive.info/music/music.xml

<小时/>

嘿!你偷偷地改变了你的LogCat。

无论如何,现在的问题是图像 URL:

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

检查“a_web_url”处的数据,该数据显然位于您的服务器上......

关于java - ListView OnItemClickListener 不适用于 LazyAdapter ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13460516/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com