Доброго.
Странная вещь, в эмуляторе апи 21 RecyclerView ведёт себя корректно, но в других он не выводит список на экран, хотя происходит вызов notifyDataSetChanged
код адаптера
package com.example.weather.app.adapter.recyclerView;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.example.weather.R;
import com.example.weather.eventBus.ClickItemRecyclerView;
import org.greenrobot.eventbus.EventBus;
import java.util.List;
public class AdapterFindCity extends RecyclerView.Adapter<AdapterFindCity.ViewHolder> {
public static class ViewHolder extends RecyclerView.ViewHolder {
private TextView nameEnCity, country;
private LinearLayout layout;
public ViewHolder(@NonNull View itemView) {
super(itemView);
layout = itemView.findViewById(R.id.find_city_layout);
nameEnCity = itemView.findViewById(R.id.tv_name_en_city_adapter);
country = itemView.findViewById(R.id.tv_country_adapter);
}
}
private List<ItemAdapterFindCity> list;
public AdapterFindCity(List<ItemAdapterFindCity> list) {
this.list = list;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View view = inflater.inflate(R.layout.find_city_adapter, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
ItemAdapterFindCity item = list.get(position);
holder.country.setText(item.getCountry().trim());
if (item.getNameCityEN() != null)
holder.nameEnCity.setText(item.getNameCityEN().trim());
holder.layout.setOnClickListener(view -> {
EventBus.getDefault().post(new ClickItemRecyclerView(list.get(position).getIdWeather()));
((Activity) holder.itemView.getContext()).finish();
});
}
@Override
public int getItemCount() {
return list.size();
}
}
вот автивити
package com.example.weather.app.activities.findCity.view;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.widget.SearchView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.arellomobile.mvp.MvpAppCompatActivity;
import com.arellomobile.mvp.presenter.InjectPresenter;
import com.example.weather.R;
import com.example.weather.app.activities.findCity.presenter.PresenterFindCity;
import com.example.weather.app.adapter.recyclerView.AdapterFindCity;
import com.example.weather.app.adapter.recyclerView.ItemAdapterFindCity;
import com.google.android.flexbox.FlexboxLayout;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class FindCity extends MvpAppCompatActivity implements ViewFindCity {
@InjectPresenter
PresenterFindCity presenter;
@BindView(R.id.flex_box_container) FlexboxLayout flexboxContainer;
@BindView(R.id.recycler_list_city) RecyclerView recyclerViewCity;
@BindView(R.id.sw_city) SearchView searchView;
@BindView(R.id.tv_popular_cities) TextView tvPopularCities;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.find_city);
ButterKnife.bind(this);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
recyclerViewCity.setLayoutManager(layoutManager);
recyclerViewCity.setHasFixedSize(false);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
// presenter.setTextSearch(query);
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
presenter.setTextSearch(newText);
return false;
}
});
}
private AdapterFindCity adapterFindCity;
/**сюда приходит ссылка на array*/
@Override
public void updateRecyclerView(List<ItemAdapterFindCity> cityList) {
if (recyclerViewCity.getVisibility() == View.GONE) {
flexboxContainer.setVisibility(View.GONE);
tvPopularCities.setVisibility(View.GONE);
recyclerViewCity.setVisibility(View.VISIBLE);
adapterFindCity = new AdapterFindCity(cityList);
recyclerViewCity.setAdapter(adapterFindCity);
}
adapterFindCity.notifyDataSetChanged();
}
// @OnClick(R.id.btn_search_city)
// public void SearchCity() {
//// presenter.
// }
@Override
protected void onDestroy() {
super.onDestroy();
ButterKnife.bind(this).unbind();
presenter.disposable();
}
}