gpt4 book ai didi

java - Android AsyncTask 中的 ArrayList

转载 作者:行者123 更新时间:2023-12-01 19:28:20 24 4
gpt4 key购买 nike

如何创建一个类 AsynkTask,其中填充类 DataContainer。继续用合成数据填充 DataContainer 类。每创建一个新记录后,应将 AsynkTask 类暂停一小段时间(200 毫秒)。?

public class DataContainer  {
public ArrayList<String> mGlobalDataStore1 = initializeData();

static ArrayList<String> initializeData(){
ArrayList<String> data = new ArrayList<String>();
for (Integer i=0; i<100; i++){
data.add("Item " + i.toString());
}
return data;
}

}


public class TestTask extends AsyncTask<Character, String, ArrayList<String>> {

@Override
protected ArrayList<String> doInBackground(Character... integers) {


return null;
}

@Override
protected void onProgressUpdate(String... values) {


}

@Override
protected void onPostExecute(ArrayList<String> s) {



}

}

如何在 AsyncTask 类中实现 DataContainer 类?

public class MainActivity extends AppCompatActivity {
private ProgressBar progressBar;
private AsyncTask asyncTask;
private RecyclerView recyclerView;
private DataContainer fragment;
private TextView textView;







@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater= getMenuInflater();
inflater.inflate(R.menu.refresh, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()){
case R.id.item1:
Toast.makeText(this,"erfolgreich",Toast.LENGTH_SHORT).show();
return true;
default:
Toast.makeText(this," nicht erfolgreich",Toast.LENGTH_SHORT).show();
}


return false;
}




@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

progressBar=findViewById(R.id.progressBar);
textView=findViewById(R.id.textView);

}

最佳答案

我知道这不是您正在寻找的答案。但 AsyncTask api 从 Android 11 开始已弃用。请阅读 this链接了解更多信息

关于java - Android AsyncTask 中的 ArrayList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59286818/

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