Android 使用通用图像加载器和Aquery从数据库加载图像
嘿,伙计们,我正在构建一个从mysql加载数据的应用程序,它填充一个listview。我在每一行都有一个imageview,我想用db中的图像填充它。实际上它是图像的路径。我使用了通用图像加载器和安卓aquery,但都不起作用,或者我做错了什么 我的代码是:Android 使用通用图像加载器和Aquery从数据库加载图像,android,mysql,android-listview,android-imageview,Android,Mysql,Android Listview,Android Imageview,嘿,伙计们,我正在构建一个从mysql加载数据的应用程序,它填充一个listview。我在每一行都有一个imageview,我想用db中的图像填充它。实际上它是图像的路径。我使用了通用图像加载器和安卓aquery,但都不起作用,或者我做错了什么 我的代码是: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); s
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.listView1);
ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean network_connected = activeNetwork != null
&& activeNetwork.isAvailable()
&& activeNetwork.isConnectedOrConnecting();
if (!network_connected) {
onDetectNetworkState().show();
} else {
if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) {
accessWebService();
registerCallClickBack();
}
if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) {
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
String skipMessage = settings.getString("skipMessage",
"NOT checked");
if (!skipMessage.equals("checked")) {
onAlertMobileData().show();
}
if (skipMessage.equals("checked")) {
accessWebService();
registerCallClickBack();
}
}
}
ImageLoader imageLoader=new ImageLoader(getApplicationContext());
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(MainActivity.this).build();
ImageLoader.getInstance();
options = new DisplayImageOptions.Builder()
.showImageForEmptyUri(R.drawable.ic_launcher_stock_custom_icon)
.showImageOnFail(R.drawable.ic_launcher_stock_custom_icon)
.resetViewBeforeLoading(true)
.cacheOnDisc(true)
.imageScaleType(ImageScaleType.EXACTLY)
.bitmapConfig(Bitmap.Config.RGB_565)
.considerExifParams(true)
.displayer(new FadeInBitmapDisplayer(300))
.build();
}
我从db获取图像的地方是:
public void ListDrawer() {
stocksList = new ArrayList<HashMap<String, String>>();
try {
JSONObject jsonResponse = new JSONObject(jsonResult);
JSONArray jsonMainNode = jsonResponse.optJSONArray("metoxes");
for (int i = 0; i < jsonMainNode.length(); i++) {
JSONObject jsonChildNode = jsonMainNode.getJSONObject(i);
name = jsonChildNode.optString("name");
String price = jsonChildNode.optString("price");
String price1 = jsonChildNode.optString("price1");
String price2 = jsonChildNode.optString("price2");
String price3 = jsonChildNode.optString("price3");
String price4 = jsonChildNode.optString("price4");
String price5 = jsonChildNode.optString("price5");
String price6 = jsonChildNode.optString("price6");
String price7 = jsonChildNode.optString("price7");
String price8 = jsonChildNode.optString("price8");
String price9 = jsonChildNode.optString("price9");
String price10 = jsonChildNode.optString("price10");
String price11 = jsonChildNode.optString("price11");
String price12 = jsonChildNode.optString("price12");
String price13 = jsonChildNode.optString("price13");
String price14 = jsonChildNode.optString("price14");
String price15 = jsonChildNode.optString("price15");
imageUri = jsonChildNode.optString("image");
image = (ImageView)findViewById(R.id.imagestartinglist);
loader.displayImage(imageUri, image, options);
stocksList.add(createStockList(name, price, price1, price2,
price3, price4, price5, price6, price7, price8, price9,
price10, price11, price12, price13, price14, price15));
}
} catch (Exception e) {
Intent intent1 = new Intent(MainActivity.this,
RefreshActivity.class);
startActivityForResult(intent1, 0);
}
/*AQuery aq = new AQuery(MainActivity.this);
boolean memCache = true;
boolean fileCache = true;
aq.id(R.id.imagestartinglist).image(imageUri, memCache, fileCache);*/
//imageLoader.DisplayImage(imageUri, image);
String[] from = { "name", "price" };
int[] to = { R.id.stock_name, R.id.stock_price };
SimpleAdapter simpleAdapter = new SimpleAdapter(this, stocksList,
R.layout.list_item, from, to);
listView.setAdapter(simpleAdapter);
}
有人能帮我吗??我已经添加了两个库来构建path,并且
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
那些许可证在我的舱单上。。我遗漏了什么???您是否正确获取了json数据?这是我的json数据文件看看我的ans如何使用AndroidQuery我从来没有使用过Aquery,但使用通用图像加载器我的一个项目将尝试这个,我会让你知道