0
I have a problem that, I try to show the data of a Recyclerview that I take the data on the web (until then ok), I receive the data and when I set the Adapter in Recyclerview nothing happens, follow the code:
Java app.
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);
}
}
onCreate da Activity
/* 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 of the tutorial Alura.
In your logcat, some error appears?!
– viana
Why are you creating two layoutManager? Is there something wrong that is not right in this code!
– viana
logcat no error appears, and the two layouts were just a mistake I copied, created only one
– Windows87