【问题标题】:How can I fetch the images in order in parse using ANDROID如何使用ANDROID按顺序获取图像
【发布时间】:2015-08-22 16:33:55
【问题描述】:

我已成功从 parse 下载图像,但问题是它们没有按顺序获取。图像正在后台进程中下载,我将它们插入 arrayList 以填充 listView。如何检查图像在 arrayList 中的插入顺序是否与它们在解析后端中的顺序相同?到目前为止,我发现有些图像的尺寸较小,因此可以快速获取它们并首先插入到列表中,但这不是我想要的。我希望它们的顺序相同。有什么可能的解决方案?

public class FetchClients extends AppCompatActivity {
public static ArrayList<String> objectID = new ArrayList<String>();
private ArrayList<String> name              = new ArrayList<String>();
private ArrayList<String> address           = new ArrayList<String>();
private ArrayList<Integer> unitNumber       = new ArrayList<Integer>();
private ArrayList<String> city              = new ArrayList<String>();
private ArrayList<String> state             = new ArrayList<String>();
private ArrayList<String> zipCode           = new ArrayList<String>();
private ArrayList<byte[]> customerImage     = new ArrayList<byte[]>();
private ListView listView;
private ContactsAdapter contactsAdapter;
ImageView testView;

/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.customers_list);

  //  contactsAdapter =
    listView = (ListView) findViewById(R.id.list_view);

    loadListView(); // load data in listView


    listView.setFocusable(true);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id)
        {

            Intent intent = new Intent(getApplicationContext(),ClientDetails.class);
            intent.putExtra("name", name.get(position));
            intent.putExtra("address", address.get(position));
            intent.putExtra("unitNumber",unitNumber.get(position));
            intent.putExtra("city", city.get(position));
            intent.putExtra("state", state.get(position));
            intent.putExtra("zipCode", zipCode.get(position));
            intent.putExtra("customerImage", customerImage.get(position));
            startActivity(intent);

        }
    });
}

public void loadListView(){
    ParseQuery<ParseObject> query = ParseQuery.getQuery("Customer");
    query.findInBackground(new FindCallback<ParseObject>() {
        @Override
        public void done(List<ParseObject> customer, com.parse.ParseException e) {
            if (e == null) {
                for (int i = 0; i < customer.size(); i++) {
                    objectID.add(customer.get(i).getObjectId());
                    name.add(customer.get(i).getString("accountHolder"));
                    address.add(customer.get(i).getString("streetAddress"));
                    unitNumber.add(customer.get(i).getInt("unitNumber"));
                    city.add(customer.get(i).getString("city"));
                    state.add(customer.get(i).getString("state"));
                    zipCode.add(customer.get(i).getString("zipCode"));

                    try {
                        ParseFile imageFile = (ParseFile) customer.get(i).get("customerImage");

                        imageFile.getDataInBackground(new GetDataCallback() {
                            public void done(byte[] data, ParseException e) {
                                if (e == null) {
                                    Log.d("test", "We've got data in data.");
                                    customerImage.add(data);
                                    //contactsAdapter.notifyDataSetChanged();
                                    listView.setAdapter(new ContactsAdapter(getApplicationContext(), name
                                            , city, customerImage)); //set custom ListAdapter

                                } else {
                                    Log.d("test", "There was a problem downloading the data.");
                                }
                            }
                        });
                    }catch(Exception e1){e1.printStackTrace();}
                }

            } else {
                e.printStackTrace();
                Toast.makeText(getApplicationContext(), "Unable to get Values", Toast.LENGTH_SHORT).show();
            }
        }
    });
}

【问题讨论】:

    标签: java android database parse-platform


    【解决方案1】:

    您必须从后端添加一些带有图像 URL 的排序 ID,以便您可以决定将该图像放在 Array 中的哪个位置。

    【讨论】:

    • 是的,这可能是一个可能的解决方案。但是还有其他更好的解决方案吗?目前,我实施的另一个解决方案是使用 getData() 而不是进入后台
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-24
    • 1970-01-01
    • 1970-01-01
    • 2021-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多