Hi all I have a bit of a weird problem with my app I am populating a list in a RecyclerView using an Async Task. Everything works OK but when there is no data to populate I want to inflate another layout to show an error message.
public class generateAds extends AsyncTask<String, Void, Void> {
protected Void doInBackground(String... params)
{
//Filling the list -This part is OK
}
//Here is my problem
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
spinner.setVisibility(View.GONE);
if(ads.size() > 0)
{
if (isFirstSearch)
{
isFirstSearch = false;
cardAdapter = new CardAdapter(context, ads);
recyclerViewZone.setAdapter(cardAdapter);
recyclerViewZone.setItemAnimator(new DefaultItemAnimator());
}
else
{
for (int i = 0; i < ads.size(); i++) {
cardAdapter.add(ads.get(i), cardAdapter.getItemCount());
}
}
generatedAdsFromScroll = false;
}
else
{
//This doesn't inflate
try
{
rootView = inflater.inflate(R.layout.error_internet_connection,container,false);
}catch (Exception e)
{
e.printStackTrace(); //No exception thrown for some reason
}
}
}
}
So in my onPostExecute After I check if the list ADS contains something it should go and inflate my layout. The weird thing is that it does read it, but no layout is shown on the screen it doesnt throw any exceptions of any sort. What could be the problem?