gpt4 book ai didi

java - 如何在类内部执行从类内部适配器访问的内部类

转载 作者:行者123 更新时间:2023-12-01 09:33:27 28 4
gpt4 key购买 nike

我在访问 Asynctask<> 时遇到问题,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

}

最佳答案

尝试这样,

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());
}
}

关于java - 如何在类内部执行从类内部适配器访问的内部类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39202512/

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