I am trying to get data that I put into a Backendless console and show it in my android application but the data is not showing up. It just shows a blank activity/screen. It’s not crashing either. Frankly, I’d be more pleased if it was. Any help would be greatly appreciated!
private List<Cake> list;
private Context context;
public CakeAdapter(Context context, List<Cake> list) {
this.context = context;
this.list = list;
}
@Override
public CakeHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_cake, parent, false);
return new CakeHolder(view);
}
@Override
public void onBindViewHolder(CakeHolder holder, int position) {
final Cake cake = list.get(position);
holder.type.setText(cake.getType());
holder.description.setText(cake.getDescription());
// holder.type.setText(“I dont know.”);
// holder.description.setText(“Just some random text. I am in the mood for pizza.”);
}
@Override
public int getItemCount() {
return list.size();
}
public class CakeHolder extends RecyclerView.ViewHolder {
//Setup Views
CardView card;
TextView type;
TextView description;
public CakeHolder(View itemView) {
super(itemView);
//Assign views by ID
card = (CardView) itemView.findViewById(R.id.cakecard);
type = (TextView) itemView.findViewById(R.id.type);
description = (TextView) itemView.findViewById(R.id.description);
}//Setup Views
private Toolbar toolbar;
private SwipeRefreshLayout swipe;
private FloatingActionButton fab;
private RecyclerView recycler;
//Setup adapter
private CakeAdapter adapter;
//Setup Cake
private List<Cake> Cake = new ArrayList<>();
//Setup backend call
private BackendlessCollection<Cake> cakes;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_Cake);
//Setup toolbar
toolbar = (Toolbar) findViewById(R.id.bar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
//Setup SwipeView
swipe = (SwipeRefreshLayout) findViewById(R.id.swipe);
swipe.setOnRefreshListener(this);
swipe.setColorSchemeResources(R.color.colorPrimaryDark,
R.color.blade,
android.R.color.holo_orange_light,
R.color.fruit);
//Setup Recyclerview
recycler = (RecyclerView) findViewById(R.id.recycler);
recycler.setItemAnimator(new DefaultItemAnimator());
recycler.setLayoutManager(new LinearLayoutManager(this));
recycler.setHasFixedSize(true);
adapter = new CakeAdapter(this, cake);
recycler.setAdapter(adapter);
//Setup FAB and attach to recycler
fab = (FloatingActionButton) findViewById(R.id.fab);
fab.attachToRecyclerView(recycler);
fab.setOnClickListener(this);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
supportFinishAfterTransition();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onClick(View v) {
//do something later
}
@Override
public void onRefresh() {
refreshCakes();
if (swipe.isRefreshing()) {
swipe.setRefreshing(false);
}
}
private void refreshCakes() {
QueryOptions query = new QueryOptions();
query.setPageSize(20);
BackendlessDataQuery queries = new BackendlessDataQuery(query);
Backendless.Data.of(Cake.class).find(queries, new AsyncCallback<BackendlessCollection<Cake>>() {
@Override
public void handleResponse(BackendlessCollection<Cake> cakeBackendlessCollection) {
cakes = cakeBackendlessCollection;
addMore(cakeBackendlessCollection);
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
Log.d(“Cake”, "Error: " + backendlessFault.getMessage());
}
});
}
private void addMore(BackendlessCollection<Cake> next) {
cake.addAll(next.getCurrentPage());
adapter.notifyDataSetChanged();
}
Hi Nick,
If you set a breakpoint in the following code, is it hit? Does the collection you get contain any data?
public void handleResponse(BackendlessCollection<Cake> cakeBackendlessCollection) {
cakes = cakeBackendlessCollection;
addMore(cakeBackendlessCollection);
}
Regards,
Mark
Could you explain to me what a breakpoint is?
It is a mechanism to pause execution of the code on a specific line of code to inspect variable and make sure that the code gets to the point where you expect it to me. Try googling how to set breakpoints in Android Studio (I assume that’s what you use).
Mark
I got a callback error: Callback error: Unable to retrieve data - unknown entity
Could this be why?
Sure, that explains why you’re not seeing any data - it simply is not returned back to your app. What is the name of the table where you need to load data from?
Cakes
Okay… and what is the name of your class? (hint, hint… they must match…)
Cake… I had the names different…
I’m ashamed to be called a programmer for making that small mistake. The data is loading properly now.
Thanks! You just earned me an A!
Hi Nick Breus
I am having issues in retriving data in recycler view can you help me by sending your code i will be really glad if u help me.
I am waiting for your reply.
E-mail id:-kiitapk1@gmail.com