我在访问Asynctask<>时遇到问题在A类和A类中有一个适配器(RecyclerViewAdapter),它想要访问扩展Asynctask的类<>
简而言之,就像这样:
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
RecyclerView recyclerView;
SimpleRecyclerAdapter simpleRecyclerAdapter;
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(MainActivity.this);
recyclerView.setAdapter(SimpleRecyclerAdapter);
public class getData extends AsyncTask<>{
....
}
}
这是SimpleRecyclerAdapter
public class SimpleRecyclerAdapter extends RecyclerView.Adapter<SimpleRecyclerAdapter.VersionViewHolder> {
//from this I would like to execute getData class
}
答案 0 :(得分:1)
试试这个,
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
RecyclerView recyclerView;
SimpleRecyclerAdapter simpleRecyclerAdapter;
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(MainActivity.this);
new GetData().execute();
}
public class SimpleRecyclerAdapter extends RecyclerView.Adapter<SimpleRecyclerAdapter.VersionViewHolder> {
//from this I would like to execute getData class
}
public class GetData extends AsyncTask<>{
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... voids) {
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
recyclerView.setAdapter(new SimpleRecyclerAdapter());
}
}