我已經能夠從Parse中提取字符串數據並將其設置爲textviews,但我無法獲取圖像文件並將其設置在imageview中,我嘗試使用Byte方法,但有沒有成功,並在data.length上出現錯誤。繼承人我的代碼:從Parse中加載圖片並設置在圖片查看
public class mygardenDetail extends Activity {
String name;
//String image;
String kgsays;
String care;
String tips;
String image;
Context context;
ImageLoader imageLoader = new ImageLoader(this);
List<ParseObject> ob;
private List<PlantListitems> plantlist = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the view from singleitemview.xml
setContentView(R.layout.mygarden_detail);
//new mygardenDetail.RemoteDataTask().execute();
imageLoader = new ImageLoader(context);
Intent i = getIntent();
// Get the result of rank
name = i.getStringExtra("name");
//Get the result of country
// kgsays = i.getStringExtra("kgsays");
// Get the result of country
//care = i.getStringExtra("care");
// Get the result of population
//tips = i.getStringExtra("tips");
// Get the result of flag
// image = i.getStringExtra("image");
// Locate the TextViews in singleitemview.xml
TextView txtName = (TextView) findViewById(R.id.name);
final TextView txtKGsays = (TextView) findViewById(R.id.KGsays);
final TextView txtCare = (TextView) findViewById(R.id.Care);
final TextView txtTips = (TextView) findViewById(R.id.Tips);
// Locate the ImageView in singleitemview.xml
final ImageView imgflag = (ImageView) findViewById(R.id.image);
//Set values in containers
txtName.setText(name);
imageLoader.DisplayImage(image, imgflag);
ParseQuery query = new ParseQuery<>("Plants2");
query.whereEqualTo("plantName", (name));
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> listCountry, ParseException e) {
for (ParseObject country : listCountry) {
// Locate images in flag column
ParseFile image = (ParseFile) country.get("image");
//PlantListitems map = new PlantListitems();
txtKGsays.setText((String) country.get("KGsays"));
txtCare.setText((String) country.get("Care"));
txtTips.setText((String) country.get("tips"));
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
imgflag.setImageBitmap(bmp);
//plantlist.add(map);
//imageLoader.DisplayImage(image, imgflag);
}
}
});
}
}
代碼用於通過意圖在列表視圖中顯示:
// RemoteDataTask AsyncTask
private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
// Create the array
worldpopulationlist = new ArrayList<WorldPopulation>();
try {
// Locate the class table named "Country" in Parse.com
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
"Plants2");
// Locate the column named "ranknum" in Parse.com and order list
// by ascending
query.orderByAscending("plantName");
ob = query.find();
for (ParseObject country : ob) {
// Locate images in flag column
ParseFile image = (ParseFile) country.get("image");
WorldPopulation map = new WorldPopulation();
map.setName((String) country.get("plantName"));
map.setType((String) country.get("type"));
map.setPlot((String) country.get("plotSize"));
map.setImage(image.getUrl());
worldpopulationlist.add(map);
}
} catch (ParseException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}
您可以使用任何庫Glide,Universal或picasso在imageview上顯示它 –
我該如何實現此方法? – user4682589
參考這個答案http://stackoverflow.com/a/39972276/3946958 ...他們已經使用滑行庫 –