“ SpotsDialog显示了如何解决运行代码的私有访问错误。”
>我的MainActivity.java类
RecyclerView listWebsite;
RecyclerView.LayoutManager layoutManager;
NewsService mService;
ListSourceAdapter adapter;
AlertDialog dialog;
SwipeRefreshLayout swipeRefreshLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//init cache
Paper.init(this);
//init Services
mService = Common.getNewsService();
//init View
swipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.swipeRefresh);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
loadWebsiteSource(true);
}
});
listWebsite = (RecyclerView)findViewById(R.id.list_source);
listWebsite.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this);
listWebsite.setLayoutManager(layoutManager);
dialog = new SpotsDialog(this);
loadWebsiteSource(false);
}
private void loadWebsiteSource(boolean isrefreshed) {
if (!isrefreshed)
{
String cache = Paper.book().read("cache");
if (cache != null && !cache.isEmpty())
{
Website website = new Gson().fromJson(cache,Website.class);// Convert cache from JSON to obj.
adapter = new ListSourceAdapter(getBaseContext(),website);
adapter.notifyDataSetChanged();
listWebsite.setAdapter(adapter);
}
else //if not have cache
{
dialog.show();
//Fetch new data
mService.getSource().enqueue(new Callback<Website>() {
@Override
public void onResponse(Call<Website> call, Response<Website> response) {
adapter = new ListSourceAdapter(getBaseContext(),response.body());
adapter.notifyDataSetChanged();
listWebsite.setAdapter(adapter);
//Save the cache
Paper.book().write("cache",new Gson().toJson(response.body()));
//Dismiss refresh programming
swipeRefreshLayout.setRefreshing(false);
}
@Override
public void onFailure(Call<Website> call, Throwable t) {
}
});
}
}
else //If from Swipe to Refresh
{
dialog.show();
//Fetch new data
mService.getSource().enqueue(new Callback<Website>() {
@Override
public void onResponse(Call<Website> call, Response<Website> response) {
adapter = new ListSourceAdapter(getBaseContext(),response.body());
adapter.notifyDataSetChanged();
listWebsite.setAdapter(adapter);
//Save the cache
Paper.book().write("cache",new Gson().toJson(response.body()));
}
@Override
public void onFailure(Call<Website> call, Throwable t) {
}
});
}
}
}
此行给出了错误
dialog = new SpotsDialog(this);
这是错误的解决方法