gpt4 book ai didi

android - 从 Parse.com 拉取图像

转载 作者:行者123 更新时间:2023-11-29 01:46:39 25 4
gpt4 key购买 nike

我已将一些图像从我的移动相册保存到 Parse.com,我正在尝试在另一个 Activity 中获取图像并将其显示在 ListView 中,但我无法做到。我已经搜索了文档但无法解决它。这是我的类(class)。

public class GetImage extends Activity {
// Declare Variables
ListView listview;
List<ParseObject> ob;
ProgressDialog mProgressDialog;
ListAdapter adapter;

private ArrayList imagelist = null;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the view from listview_main.xml
setContentView(R.layout.listview_main);
// Execute RemoteDataTask AsyncTask
new RemoteDataTask().execute();
}

借助AsyncTask

private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Create a progressdialog
mProgressDialog = new ProgressDialog(GetImage.this);
// Set progressdialog title
mProgressDialog.setTitle("Parse.com Custom ListView");
// Set progressdialog message
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
// Show progressdialog
mProgressDialog.show();
}

@Override
protected Void doInBackground(Void... params) {
// Create the array
imagelist = new ArrayList<Images>();
try {
// Locate the class table named "Country" in Parse.com
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
"Image");
query.orderByAscending("ImageFile");
ob = query.find();
for (ParseObject pb : ob) {

ParseFile image = (ParseFile) Image.get("ImageFile");

}
} catch (ParseException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}

@Override
protected void onPostExecute(Void result) {
// Locate the listview in listview_main.xml
listview = (ListView) findViewById(R.id.listView1);
// Pass the results into ListViewAdapter.java
adapter = new ListAdapter(GetImage.this,
imagelist);
// Binds the Adapter to the ListView
listview.setAdapter(adapter);
// Close the progressdialog
mProgressDialog.dismiss();
}
}}

如果有任何用于访问 Parse.com 上的数据的 API,请帮忙谢谢!

最佳答案

在您的代码中,一切都很好。你必须填写

imagelist = new ArrayList<Images>(); 

当您在 doInBackground(Void... params) 中获取图像时,尝试添加 imagelist.add(Image.get("ImageFile")); 在您的 Async 的 Task doInBackground(Void... params) 方法。就这些。

关于android - 从 Parse.com 拉取图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21037696/

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