从索引为0的Arraylist获取数据

时间:2018-05-07 15:22:02

标签: android arrays indexing

我想在Arraylist中获取第一个数据,但是我的代码遇到了字符串img包含空数据的问题。这是我的代码:

private List<String> imagedUploaded = new ArrayList<>();
....
private void uploadImageFile(List<Uri> imgUrl) {
    for (Uri uri : imgUrl) {
        StorageReference fileToUpload = storageRef.child(productID).child(getFileName(uri));
        fileToUpload.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {

                listImageSelectedAdapter.notifyDataSetChanged();
                imagedUploaded.add(taskSnapshot.getDownloadUrl().toString()); // get image downloadurl
                **defImg = imagedUploaded.get(0);**
                productImage = product_Ref.child("product_image").child(productID);
                productImage.setValue(imagedUploaded);
                selectedImages.clear();

            }

        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                Toast.makeText(getContext(), "Upload Image Failed", Toast.LENGTH_SHORT).show();
            }
        });
    }

}

这时我想调用索引结果

uploadProduct() {
    product = product_Ref.child(path1).child(path2).child(path3).child(productID);
    DataUploadProduct data = new DataUploadProduct();

    data.setName(etProductName.getText().toString());
    data.setPrice(etPrice.getText().toString());

    **data.setDef_image(defImg);**
    data.setWeight(etWeight.getText().toString());
    data.setDescription(etDescription.getText().toString());
    product.setValue(data);
}

在这种情况下imagedUploaded包含:

0 = http://www.url.com1
1 = http://www.url.com2
2 = http://www.url.com3
3 = http://www.url.com4

我想获取数据只有索引0,我该怎么做?

0 个答案:

没有答案