RecyclerView does not show data

0

I have a problem that, I try to show the data of a RecyclerView that I get the data on the web (Until then ok), I get the data and when I set the adapter in RecyclerView nothing happens, it follows the code: / p>

App.java

public class App {

    private String imageUrl;
    private String appName;
    private String description;
    private View.OnClickListener downloadFunction;

    public App(String appName, String description, String imageUrl, View.OnClickListener downloadFunction){
        this.appName = appName;
        this.description = description;
        this.imageUrl = imageUrl;
        this.downloadFunction = downloadFunction;
    }

    public String getImageUrl(){
        return imageUrl;
    }

    public String getAppName(){
        return appName;
    }

    public String getDescription(){
        return description;
    }

    public View.OnClickListener getdownloadFunction(){
        return downloadFunction;
    }
}

StoreItemAdapter.java

public class StoreItemAdapter extends RecyclerView.Adapter {

    private final List<App> apps;
    private Context context;

    public StoreItemAdapter(List<App> apps, Context context){
        this.apps = apps;
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.storelist, parent, false);
        storeViewHolder holder = new storeViewHolder(view);

        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        storeViewHolder viewHolder = (storeViewHolder) holder;
        App app  = apps.get(position);

        Picasso.with(context).load(app.getImageUrl()).resize(90, 90).into(viewHolder.imageApp);
        viewHolder.appName.setText(app.getAppName());
        viewHolder.description.setText(app.getDescription());
        viewHolder.downloadApp.setOnClickListener(app.getdownloadFunction());
    }

    @Override
    public int getItemCount() {
        return apps.size();
    }
}

class storeViewHolder extends RecyclerView.ViewHolder {
    final ImageView imageApp;
    final TextView appName;
    final TextView description;
    final TextView downloadApp;

    public storeViewHolder(View view){
        super(view);
        imageApp = (ImageView) view.findViewById(R.id.imageItem);
        appName = (TextView) view.findViewById(R.id.appNameItem);
        description = (TextView) view.findViewById(R.id.descriptionItem);
        downloadApp = (TextView) view.findViewById(R.id.downloadItem);
    }

}

Activity onCreate

/* Código pra cima */

RecyclerView recyclerView;
private List<App> apps = new ArrayList<App>();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_asura);

    View.OnClickListener downloadFunction = new View.OnClickListener(){
        @Override
        public void onClick(View v){
            Toast.makeText(AsuraActivity.this, "iai", Toast.LENGTH_SHORT).show();
        }
    };

    recyclerView = (RecyclerView) findViewById(R.id.testList);
    apps.add(new App("eae", "eaer", "http://1.bp.blogspot.com/-j7IBVPTLmRc/UKU0Cdq3cgI/AAAAAAAABM0/3qkRPAuSefE/s1600/Logo+Legal+9.jpg", downloadFunction));
    recyclerView.setAdapter(new StoreItemAdapter(apps, this));

    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
    recyclerView.setLayoutManager(layoutManager);

   /* Código pra baixo */

Can anyone identify an error? I followed the steps in the Alura tutorial.

    
asked by anonymous 19.08.2017 / 03:05

2 answers

0

The same problem was not the code, it was just that my RecyclerView was under a LinearLayout that was occupying the entire screen

    
27.08.2017 / 05:39
1

In the declaration of your adapter do:

public class StoreItemAdapter extends RecyclerView.Adapter<StoreItemAdapter.storeViewHolder> {

For your ViewHolder to be recognized.

    
21.08.2017 / 20:03