【发布时间】:2018-05-31 10:58:20
【问题描述】:
请检查更新的代码。它是说 arraylist 为空,同时试图从 oncreate 方法中获取元素。顺便说一句,我将元素添加到内部类中的数组列表中。 任何帮助将不胜感激。 谢谢..
private ArrayList<String> imageName;
ListView listView;
ArrayList<String> test;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = this;
listView = findViewById(R.id.clipslistview);
test = new ArrayList<>();
credentialProvider();
setTransferUtility();
getAll();
Toast.makeText(context, test.get(0)+"", Toast.LENGTH_SHORT).show();
}
Thread thread = new Thread(){
public void run(){
final ListObjectsV2Request req = new ListObjectsV2Request().withBucketName("bucket-1234314-**********").withStartAfter(".jpg").withMaxKeys(10);
ListObjectsV2Result result;
imageNames = new ArrayList<>();
result = amazonS3Client.listObjectsV2(req);
for (S3ObjectSummary objectSummary :
result.getObjectSummaries()) {
clipNames.add(objectSummary.getKey()+"");
Log.d("TEEEST", objectSummary.getKey());
}
}
};
【问题讨论】:
-
那个线程被调用了吗?
-
为什么需要一个单独的线程来将数据添加到列表中?你是从哪里开始的?
-
因为中间有网络操作线程。所以我将我的元素添加到数组列表中。
标签: java android android-studio arraylist