Error : on a null object reference, SavedInstanceState rotation recyclerview - java

I want to create savedInstanceState that will save/keep data when display is rotating landscape or portrait, but it keep crashing when i try to rotate the display, and showing error "on a null object reference,
Here is some code for my Adapter :
public class ListMovieAdapter extends RecyclerView.Adapter<ListMovieAdapter.CardViewViewHolder> {
Context context;
ArrayList<Movie.ResultsBean> listMovie;
ProgressDialog progressBar;
public ListMovieAdapter(Context context, ArrayList<Movie.ResultsBean> listMovie) {
this.listMovie = listMovie;
this.context = context;
progressBar = new ProgressDialog(this.context);
}
public ArrayList<Movie.ResultsBean> getListMovie() {
return listMovie;
}
public void setListMovie(ArrayList<Movie.ResultsBean> movieList) {
this.listMovie = movieList;
notifyDataSetChanged();
}
and here is some of my Fragment code :
public class MovieFragment extends Fragment {
View v;
private RecyclerView myrecyclerview;
private Parcelable mRecyclerState;
private ListMovieAdapter listMovieAdapter;
private ArrayList<Movie> listMovie = new ArrayList<>();
private MutableLiveData<ArrayList<Movie.ResultsBean>> dataMovies = new MutableLiveData<>();
private ProgressDialog progressBar;
public static String BASE_URL = "https://api.themoviedb.org";
public static String CATEGORY = "upcoming";
public static int PAGE = 1;
public static String API_KEY = "ce7feeb6af94d9372180d04db1bc755d";
public static String LANGUAGE = "en-US";
private static final String SAVEINSTANCE_RECYCLERSTATE = "RecyclerState";
private static final String SAVEINSTANCE_LIST = "movielist";
public MovieFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup viewGroup, #Nullable Bundle savedInstanceState) {
v = inflater.inflate(R.layout.fragment_movie, viewGroup, false);
myrecyclerview = v.findViewById(R.id.rv_fragmovie);
myrecyclerview.setLayoutManager(new LinearLayoutManager(getActivity()));
progressBar = new ProgressDialog(getContext());
if (savedInstanceState == null) {
fetchJSON();
}else{
mRecyclerState = savedInstanceState.getParcelable(SAVEINSTANCE_RECYCLERSTATE);
listMovieAdapter.setListMovie((ArrayList)savedInstanceState.getParcelableArrayList(SAVEINSTANCE_LIST));
myrecyclerview.getLayoutManager().onRestoreInstanceState(mRecyclerState);
}
return v;
}
private void fetchJSON() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
ApiInterface apiInterface = retrofit.create(ApiInterface.class);
Call<Movie> call = apiInterface.listOfMovie(CATEGORY, API_KEY, LANGUAGE, PAGE);
call.enqueue(new Callback<Movie>() {
#Override
public void onResponse(Call<Movie> call, Response<Movie> response) {
Movie results = response.body();
List<Movie.ResultsBean> listMovie = results.getResults();
ListMovieAdapter listMovieAdapter = new ListMovieAdapter(getContext(),
(ArrayList<Movie.ResultsBean>) listMovie);
myrecyclerview.setAdapter(listMovieAdapter);
}
#Override
public void onFailure(Call<Movie> call, Throwable t) {
showDialogLoad(false);
showDialogFail(true);
}
});
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
listMovie = new ArrayList<>();
}
#Override
public void onSaveInstanceState(Bundle outState) {
mRecyclerState = myrecyclerview.getLayoutManager().onSaveInstanceState();
outState.putParcelable(SAVEINSTANCE_RECYCLERSTATE,mRecyclerState);
outState.putParcelableArrayList(SAVEINSTANCE_LIST,(ArrayList<? extends Parcelable>) listMovieAdapter.getListMovie());
super.onSaveInstanceState(outState);
}
and then some error log :
java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.ArrayList com.ilham.mymoviecatalogue.adapter.ListMovieAdapter.getListMovie()' on a null object reference
at com.ilham.mymoviecatalogue.fragment.MovieFragment.onSaveInstanceState(MovieFragment.java:106)

Create a global variables
private static final String SCROLL_POSITION = "SCROLL_POSITION";
private RecyclerView movieGrid;
private GridLayoutManager layoutManager;
For onSaveInstanceState
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(SCROLL_POSITION, ((LinearLayoutManager)movieGrid.getLayoutManager()).findFirstVisibleItemPosition());
}
Then below that add:
#Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
final int position = savedInstanceState.getInt(SCROLL_POSITION);
movieGrid.postDelayed(new Runnable() {
public void run() {
movieGrid.scrollToPosition(position);
}
}, 300);
}
Note, the last number 300 should be adjusted accordingly, to test if it is returning to the position you were last in instead of resetting your position to the top upon rotation.

Related

Attempt to invoke virtual method 'void.estate.view.adapter.plucking.EmployeePluckingSessionAdapter.setList(java.util.List)' on a null object reference

I am getting this error but I cannot find the reason.
This is my code of Adapter.
public class EmployeePluckingSessionAdapter extends RecyclerView.Adapter<EmployeePluckingSessionAdapter.EmployeePluckingSessionAdapterHolder> {
private SubSessionListActivity.AdapterEvents adapterEvents;
private List<EmployeePluckingCollectionSummary> employeePluckingCollectionSummaries = new ArrayList<>();
public EmployeePluckingSessionAdapter(SubSessionListActivity.AdapterEvents adapterEvents){
this.adapterEvents = adapterEvents;
}
public void setList(List<EmployeePluckingCollectionSummary> employeePluckingCollectionSummaries){
this.employeePluckingCollectionSummaries = employeePluckingCollectionSummaries;
}
public void setAdapterEvents(SubSessionListActivity.AdapterEvents adapterEvents) {
this.adapterEvents = adapterEvents;
}
#NonNull
#Override
public EmployeePluckingSessionAdapterHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.plucking_summary_data, parent, false);
return new EmployeePluckingSessionAdapterHolder(view);
}
#Override
public void onBindViewHolder(#NonNull EmployeePluckingSessionAdapterHolder holder, int position) {
EmployeePluckingCollectionSummary employeePluckingCollectionSummary = employeePluckingCollectionSummaries.get(position);
holder.userName.setText(String.valueOf(employeePluckingCollectionSummary.getEmployeeName()));
holder.userId.setText(String.valueOf(employeePluckingCollectionSummary.getEmployeeId()));
holder.session.setText(String.valueOf(employeePluckingCollectionSummary.getSessionName()));
holder.sessionTotal.setText(String.valueOf(employeePluckingCollectionSummary.getWeight()));
}
#Override
public int getItemCount() {
return 0;
}
class EmployeePluckingSessionAdapterHolder extends RecyclerView.ViewHolder {
private final LinearLayout plucking_data;
private final TextView userName;
private final TextView userId;
private final TextView session;
private final TextView sessionTotal;
public EmployeePluckingSessionAdapterHolder(View view) {
super(view);
this.plucking_data = view.findViewById(R.id.plucking_data);
this.userName = view.findViewById(R.id.userName);
this.userId =view.findViewById(R.id.userId);
this.session = view.findViewById(R.id.session);
this.sessionTotal = view.findViewById(R.id.sessionTotal);
}
}
}
This is my code of Activity.
public class PluckingChecklistReportActivity extends AppCompatActivity {
private PluckingCollectionViewModel pluckingCollectionViewModel;
RecyclerView recyclerView;
List<EmployeePluckingCollectionSummary> pluckingSummary = new ArrayList<>();
LinearLayoutManager linearLayoutManager;
EmployeePluckingSessionAdapter employeePluckingSessionAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_plucking_checklist_report);
pluckingCollectionViewModel = new ViewModelProvider(this).get(PluckingCollectionViewModel.class);
recyclerView = findViewById(R.id.plucking_data);
linearLayoutManager = new LinearLayoutManager(this);
recyclerView.setAdapter(employeePluckingSessionAdapter);
recyclerView.setLayoutManager(linearLayoutManager);
pluckingCollectionViewModel.getEmployeePluckingSessionSummary().observe(this, new Observer<List<EmployeePluckingCollectionSummary>>() {
#Override
public void onChanged(List<EmployeePluckingCollectionSummary> employeePluckingCollectionSummaries) {
pluckingSummary = employeePluckingCollectionSummaries;
employeePluckingSessionAdapter.setList(pluckingSummary);
}
});
}
}
I found that "pluckingSummary" list is null. I don't know how to set values to the list. I tried to set the values to arrayList after convert it into JSONObject but it did not work as well. I get values correctly when I use System.out.println(new Gson().toJson(employeePluckingCollectionSummaries));

Cannot call method of RecyclerView adapter from an activity

I am trying to set the data for recycler view to display from an AsyncTask. I am calling the method setdataEntries from the postExecute of inner class AsyncTask. But the android studio is showing me error could not find the method.
Adapter class
public class EntryAdapter extends RecyclerView.Adapter<EntryAdapter.ViewHolder> {
List<UserTuple> entries;
final private itemClickListener mOnClickListener;
public interface itemClickListener{
void onItemClick(UserTuple utuple);
}
public EntryAdapter(itemClickListener clickhandler) {
mOnClickListener = clickhandler;
}
public void setdataEntries(List<UserTuple> Data) {
entries = Data;
notifyDataSetChanged();
}
#Override
public EntryAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.singleusertuple,parent,false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(EntryAdapter.ViewHolder holder, int position) {
holder.Username.setText(entries.get(position).getUsername());
holder.Password.setText(entries.get(position).getPassword());
}
#Override
public int getItemCount() {
return entries.size();
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private TextView Username;
private TextView Password;
private CardView card;
public ViewHolder(View itemView) {
super(itemView);
Username = itemView.findViewById(R.id.susername);
Password=itemView.findViewById(R.id.pass);
itemView.setOnClickListener(this);
}
#Override
public void onClick(View v) {
int adapterPosition = getAdapterPosition();
UserTuple ut=new UserTuple(entries.get(adapterPosition).getUsername(),entries.get(adapterPosition).getPassword());
mOnClickListener.onItemClick(ut);
}
}
}
Calling Activity
public class Usertuple extends AppCompatActivity implements EntryAdapter.itemClickListener {
private RecyclerView recyclerView ;
private RecyclerView.Adapter adapater;
private SnapHelper snapHelper;
private List<UserTuple> entries;
private ProgressBar mLoadingIndicator;
private Bundle extras;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_logins);
extras = getIntent().getExtras();
//String site= extras.getString("sitename");
mLoadingIndicator = (ProgressBar) findViewById(R.id.pb_loading_indicator);
Log.i("Logins","Size of returned list "+entries.size());
recyclerView = findViewById(R.id.recycleview);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setHasFixedSize(true);
adapater = new EntryAdapter(this);
recyclerView.setAdapter(adapater);
snapHelper= new LinearSnapHelper();
snapHelper.attachToRecyclerView(recyclerView);
dataView();
}
public void dataView() {
String site= extras.getString("sitename");
recyclerView.setVisibility(View.VISIBLE);
new FetchDataTask().execute(site);
}
#Override
public void onItemClick(UserTuple utuple) {
}
private String key(){
SharedPreferences sharedPref = getSharedPreferences(
"User", this.MODE_PRIVATE);
final String passphrase = sharedPref.getString("userid", "none");
return passphrase;
}
public void showerror(){
recyclerView.setVisibility(View.GONE);
Toast.makeText(this,"Error in retrieving",Toast.LENGTH_SHORT).show();
}
public setdata(List<UserTuple> data){
adapater.setdataEntries(data);
}
public class FetchDataTask extends AsyncTask<String, Void, List<UserTuple>> {
#Override
protected void onPreExecute() {
super.onPreExecute();
mLoadingIndicator.setVisibility(View.VISIBLE);
}
#Override
protected List<UserTuple> doInBackground(String... params) {
/* If there's no zip code, there's nothing to look up. */
if (params.length == 0) {
return null;
}
String site = params[0];
try {
AppDatabase db = Room.databaseBuilder(getApplicationContext(),AppDatabase.class, "production")
.build();
entries =db.entryDao().getSpecific(site);
for(UserTuple ut : entries){
Log.i("password",ut.getPassword());
String st = new Decryption().decrypt(ut.getPassword(),key());
Log.i("After decryption",st);
ut.setPassword(st);
}
return entries;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
#Override
protected void onPostExecute(List<UserTuple> Data) {
mLoadingIndicator.setVisibility(View.INVISIBLE);
if (Data != null) {
adapater.setdataEntries(Data);
} else {
showerror();
}
}
}
}
I want the database calls to be a background task. I don't want the activity to freeze waiting for database calls. Any ideas? Thanks
Declare adapter like
private EntryAdapter adapter;
instead of
private RecyclerView.Adapter adapater;
because RecyclerView.Adapter class does not have any method named setdataEntries but only EntryAdapter class has this method so only the object of type EntryAdapter can call setdataEntries method.
Or you can use down-casting as
((EntryAdapter)adapater).setdataEntries(data);

Get value between View Pager

I want to get value from my actvity ControlAccountPassword.java to my FragmentEditoreProfile.java, I am using view pager and tab layout, what can I use for transfer data from my activity to view pager fragment like Intent or etc.
Here is my code
ControlAccountPassword.java
public class ControlAccountPassword extends AppCompatActivity {
private TabLayout tab_Layout;
private AppBarLayout appBarLayout;
private ViewPager view_Pager;
private ImageView img1;
private String temp;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_p_change_p);
//Get Intent Data
Intent intent=getIntent();
temp=intent.getStringExtra("email");
tab_Layout=(TabLayout)findViewById(R.id.tabLayout);
appBarLayout=(AppBarLayout)findViewById(R.id.appBar);
view_Pager=(ViewPager)findViewById(R.id.viewPager);
img1=(ImageView)findViewById(R.id.imgBack);
//adding fragment
ViewPagerAdapter adapter=new ViewPagerAdapter(getSupportFragmentManager());
adapter.AddFragment(new FragmentEditProfile(),"Edit Profile");
adapter.AddFragment(new FragmentChangePassword(),"Change Password");
//adapter setting
view_Pager.setAdapter(adapter);
tab_Layout.setupWithViewPager(view_Pager);
//onClickListener
onClickBack(this);
}
public void onClickBack(ControlAccountPassword view){
img1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
ControlAccountPassword.super.onBackPressed();
System.exit(1);
}
});
}
}
FragmentEditorProfile.java
public class FragmentEditProfile extends Fragment {
View view;
private ProgressDialog progress;
private String URL;
private String name,phone,email;
private GetURL getURL=new GetURL(URL);
public FragmentEditProfile() {
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
view=inflater.inflate(R.layout.edit_profile,container,false);
return view;
}
public void getDataPelanggan(){
progress = new ProgressDialog(getActivity());
progress.setCancelable(false);
progress.setMessage("Loading. . .");
progress.show();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(getURL.GetMyURL())
.addConverterFactory(GsonConverterFactory.create())
.build();
PelangganAPI api = retrofit.create(PelangganAPI.class);
//Call<PelangganList> call = api.getPelanggan();
}}
create new class and extends Application:
public class YourClassName extends Application {
public Context context;
public static int iID;
public static String sDeviceID;
#Override
public void onCreate() {
super.onCreate();
context = getApplicationContext();
}
}
you can change public static var's value everywhere or using vars everywhere you want:
in other class:
YourClassName.sDeviceID = "EB67";
and in another class:
int iVar;
String sVar;
iVar = YourClassName.iID;
sVar = YourClassName.sDeviceID;

NullPointerException In my widgets inside a Fragment

When the method(Bill) is called the widgets that I initialized with Butterknife is returning null(noPrev and recyclerList).
In other classes like activities, I used the same method(Binding the widget with BUtterknife) and It is working well but when I tried binding my widgets inside the fragment, it always returning null.
........................................................................
public class Home extends Fragment implements BridgeInterface.BillsResponse{
#BindView(R.id.rvBillList)
RecyclerView recyclerList;
#BindView(R.id.tvNoPreviousBill)
TextView noPrev;
public List<Bill> list_of_bill = new ArrayList<>();
private BillRecyclerAdapter adapter;
private Handler h;
private Runnable r;
private View v;
public Home() {
// Required empty public constructor
}
public static Home getInstance() {
Home home = new Home();
return home;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
v = inflater.inflate(R.layout.fragment_home, container, false);
ButterKnife.bind(Home.this,v);
if(list_of_bill.size()==0){
noPrev.setVisibility(View.VISIBLE);
recyclerList.setVisibility(View.GONE);
} else{
noPrev.setVisibility(View.GONE);
recyclerList.setVisibility(View.VISIBLE);
}
return v;
}
#Override
public void onResume() {
super.onResume();
h = new Handler();
r = () -> {
BridgeInterface.GetBIlls getBIlls =
new BillsRequest(getContext());
getBIlls.request();
h.postDelayed(r,5000);
};
r.run();
}
#Override
public void Bill(List<Bill> bills) {
list_of_bill = bills;
initRecycler();
}
public void initRecycler() {
noPrev.setVisibility(View.GONE);
recyclerList.setVisibility(View.VISIBLE);
adapter = new BillRecyclerAdapter(list_of_bill);
recyclerList.setAdapter(adapter);
recyclerList.setLayoutManager(new LinearLayoutManager(getContext()));
}
}
Here's the Interface Class
public interface BridgeInterface {
interface BillsResponse{
void Bill(List<Bill> bills);
}
interface GetBIlls{
void request();
}
}
BillRequest Class;:::
public class BillsRequest implements BridgeInterface.GetBIlls {
private Context context;
private final String url = "http://"+
AppSingleton.getInstance().getIP_ADDRESS()
+"/waterdistrict/bills.php";
private Gson gson;
public BillsRequest(Context context ) {
this.context = context;
}
#Override
public void request() {
StringRequest request = new StringRequest(Request.Method.GET, url,
response -> {
gson = new GsonBuilder().create();
List<BillResponse> bill_response =
Arrays.asList(gson.fromJson(response,
BillResponse.class));
Log.d("Check", "Levl 2");
Home.getInstance().Bill(bill_response.get(0).getBills());
}, error -> {
Log.d("Error", error.toString());
});
RequestQueue queue = Volley.newRequestQueue(context);
queue.add(request);
}
}

Parse JSON data into HorizontalScrollView with Retrofit 2

I need to parse JSON data into HorizontalScrollView with Retrofit2. I parsed it into ListView succesfully, but I haven't imagination how to do it into HorizontalScrollView. Google can't give me right answer.
My code with ListView below.
P.S. I want to do HorizontalScrollView instead of ListView.
Like this.
MyForecastAdapter.java
public class MyForecastAdapter extends ArrayAdapter<Forecast> {
List<Forecast> forecastList;
Context context;
private LayoutInflater inflater;
public MyForecastAdapter(Context context, List<Forecast> objects) {
super(context, 0, objects);
this.context = context;
this.inflater = LayoutInflater.from(context);
forecastList = objects;
}
#Override
public Forecast getItem(int position) {
return forecastList.get(position);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder viewHolder;
if (convertView == null) {
View view = inflater.inflate(R.layout.activity_row, parent, false);
viewHolder = ViewHolder.create((RelativeLayout) view);
view.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
Forecast item = getItem(position);
viewHolder.textViewTemp.setText(item.getMain().getTemp());
viewHolder.textViewHumidity.setText(item.getMain().getHumidity());
return viewHolder.relativeLayout;
}
private static class ViewHolder {
public final RelativeLayout relativeLayout;
public final TextView textViewTemp;
public final TextView textViewHumidity;
private ViewHolder(RelativeLayout relativeLayout, TextView textViewTemp, TextView textViewHumidity) {
this.relativeLayout = relativeLayout;
this.textViewTemp = textViewTemp;
this.textViewHumidity = textViewHumidity;
}
public static ViewHolder create(RelativeLayout relativeLayout) {
TextView textViewTemp = (TextView) relativeLayout.findViewById(R.id.textViewTemp);
TextView textViewHumidity = (TextView) relativeLayout.findViewById(R.id.textViewHumidity);
return new ViewHolder(relativeLayout, textViewTemp, textViewHumidity);
}
}
}
ForecastList.java
public class ForecastList {
#SerializedName("list")
#Expose
private ArrayList<Forecast> forecasts = new ArrayList<>();
public ArrayList<Forecast> getForecasts() {
return forecasts;
}
public void setForecasts(ArrayList<Forecast> forecasts) {
this.forecasts = forecasts;
}
}
Forecast.java - getters/setters.
ApiService.java
public interface ApiService {
#GET("/data/2.5/forecast?q=Kirov,ru&appid=/../")
Call<ForecastList> getMyJSON();
}
RetrofitClient.java
public class RetrofitClient {
private static final String ROOT_URL = "http://api.openweathermap.org";
private static Retrofit getRetrofitInstance() {
return new Retrofit.Builder().baseUrl(ROOT_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
public static ApiService getApiService() {
return getRetrofitInstance().create(ApiService.class);
}
}
MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
forecastList = new ArrayList<>();
parentView = findViewById(R.id.parentLayout);
listView = (ListView) findViewById(R.id.listView);
ApiService apiService = RetrofitClient.getApiService();
Call<ForecastList> call = apiService.getMyJSON();
call.enqueue(new Callback<ForecastList>() {
#Override
public void onResponse(Call<ForecastList> call, Response<ForecastList> response) {
if (response.isSuccessful()) {
forecastList = response.body().getForecasts();
adapter = new MyForecastAdapter(MainActivity.this, forecastList);
listView.setAdapter(adapter);
} else {
Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_LONG).show();
}
}
#Override
public void onFailure(Call<ForecastList> call, Throwable t) {
}
});
}
You can use horizonatal Scroll View using Recycle View with LinearLayoutManager with constructor new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
Use this code .....
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
forecastList = new ArrayList<>();
parentView = findViewById(R.id.parentLayout);
LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
myList = (RecyclerView) findViewById(R.id.listView);
myList.setLayoutManager(layoutManager);
ApiService apiService = RetrofitClient.getApiService();
Call<ForecastList> call = apiService.getMyJSON();
call.enqueue(new Callback<ForecastList>() {
#Override
public void onResponse(Call<ForecastList> call, Response<ForecastList> response) {
if (response.isSuccessful()) {
forecastList = response.body().getForecasts();
adapter = new MyForecastAdapter(MainActivity.this, forecastList);
myList.setAdapter(adapter);
} else {
Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_LONG).show();
}
}
#Override
public void onFailure(Call<ForecastList> call, Throwable t) {
}
});
}
and change ListView into RecycleView in XML and in code also.....

Categories