OnCreateViewHolder is not being called for the FirebaseRecyclerAdapter<> - java

I tried to debug my program and noticed that execution is not going inside FirebaseRecyclerAdapter recyclerAdapter=new FirebaseRecyclerAdapter(
options). I have tried all the possible solutions stackoverflow offered but nothing seems to solve my problem.I m attaching my MainActivity.java, activity_main.xml and if u need any other attachment then just tell me,
thank you
MainActivity.java
public class MainActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private DatabaseReference myref;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView=(RecyclerView)findViewById(R.id.recyclerview);
recyclerView.setHasFixedSize(false);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
myref= FirebaseDatabase.getInstance().getReference().child("/blog");
FirebaseRecyclerOptions<Blog> options =
new FirebaseRecyclerOptions.Builder<Blog>()
.setQuery(myref, Blog.class)
.build();
FirebaseRecyclerAdapter<Blog,BlogViewHolder> recyclerAdapter=new FirebaseRecyclerAdapter<Blog,BlogViewHolder>(
options) {
//this is not being executed
#Override
public BlogViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.individual_row, parent, false);
return new BlogViewHolder(view);
}
#Override
public void onBindViewHolder(BlogViewHolder holder, int position, Blog model) {
holder.setTitle(model.getTitle());
holder.setDescription(model.getDescription());
holder.setImage(model.getImage());
}
};
recyclerView.setAdapter(recyclerAdapter);
}
public static class BlogViewHolder extends RecyclerView.ViewHolder {
View mView;
TextView textView_title;
TextView textView_decription;
ImageView imageView;
public BlogViewHolder(View itemView) {
super(itemView);
mView=itemView;
textView_title = (TextView)itemView.findViewById(R.id.title);
textView_decription = (TextView) itemView.findViewById(R.id.description);
imageView=(ImageView)itemView.findViewById(R.id.image);
}
public void setTitle(String title)
{
textView_title.setText(title+"");
}
public void setDescription(String description)
{
textView_decription.setText(description);
}
public void setImage(String image)
{
Picasso.with(mView.getContext())
.load(image)
.into(imageView);
}
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>

Sorry for being late, i hope you had my same error, what you are missing is this:
#Override
public void onStart() {
super.onStart();
recyclerAdapter.startListening();
}
#Override
public void onStop() {
super.onStop();
recyclerAdapter.stopListening();
}
i just lost 2 hours wondering what i was doing wrong and...well it was something like this.
Hope it helps.

Related

Android RecyclerView - How to get items selected in Fragment class which calls CustomAdapter. I know how to use get(getAbsoluteAdapterPosition()

Below recycler view code is working fine and I can Toast message what recycler view position was selected in RecycleAdapter class. But I want to know how can I get what recycler position selected in HomeFragment class?. I tried to get position by setting onclick listener to Imageview and Textview but gives error as reference to Null. Basically I want to use get(getAbsoluteAdapterPosition() in HomeFragment class to know what item selected and navigate to another Fragment. get(getAbsoluteAdapterPosition() is working as expected inside RecycleAdapter.class
binding.recyclerview.setOnClickListener is not working in HomeFragment.class. no error but no when I click on recycler views this is not shooted.
txt.setOnClickListener is giving error as null refernce which makes sense. because this is inflated in Adapter class but trying to refer in HomeFragement class. So how can I get what selected in homefragment.class. Thanks in advance
HomeFragment.class
'''
public class HomeFragment extends Fragment {
HomeFragmentBinding binding;
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.id.home_fragment, container, false);
return v;
}
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
%% some code here %%
recycleAdapter = new RecycleAdapter(list);
binding.recyclerview.setAdapter(recycleAdapter);
TextView txt = (TextView) binding.getRoot().findViewById(R.id.recycler_text);
txt.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getContext(), "Clicked on Image", Toast.LENGTH_SHORT).show();
}
});
binding.recyclerview.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getContext(), "RecyclerView clicked", Toast.LENGTH_SHORT).show();
Log.d("RecyclerViewclicked", " --- ");
}
});
'''
RecycleAdapter.class
'''
public class RecycleAdapter extends RecyclerView.Adapter<RecycleAdapter.MyViewHolder>{
RecyclerRowItemsBinding binding;
List<IconsModel> iconsList;
public RecycleAdapter(List<IconsModel> iconslist) {
this.iconsList = iconslist;
}
#NonNull
#Override
public MyViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
LayoutInflater inflator = LayoutInflater.from(parent.getContext());
View v = inflator.inflate(R.layout.recycler_row_items, parent, false);
MyViewHolder myviewholder = new MyViewHolder(v);
return myviewholder;
}
#Override
public void onBindViewHolder(#NonNull MyViewHolder holder, int position) {
IconsModel iconModel = iconsList.get(position);
holder.imageView.setImageResource(iconModel.getImageid());
holder.recyclertext.setText(iconModel.getIconName());
}
#Override
public int getItemCount() {
//return 20;
return iconsList.size();
}
class MyViewHolder extends RecyclerView.ViewHolder{
ImageView imageView;
TextView recyclertext;
public MyViewHolder(#NonNull View itemView) {
super(itemView);
imageView = itemView.findViewById(R.id.recycler_image);
recyclertext = itemView.findViewById(R.id.recycler_text);
itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
IconsModel iconModel = iconsList.get(getAbsoluteAdapterPosition());
Toast.makeText(***itemView.getContext(), "Clicked on "+iconModel.getIconName()***, Toast.LENGTH_SHORT).show();
}
});
}
}
;
}
'''
home_fragment.xml
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="1dp"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"/>
</androidx.constraintlayout.widget.ConstraintLayout>
'''
recycler_row.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:layout_gravity="center"
android:layout_margin="5dp"
android:orientation="horizontal"
app:cardCornerRadius="5dp"
app:cardElevation="5dp"
app:cardBackgroundColor="#color/home_bg_cardview">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:backgroundTint="#color/home_bg_cardview"
android:weightSum="2">
<ImageView
android:id="#+id/recycler_image"
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_weight="0.5"
app:srcCompat="?android:attr/actionModeWebSearchDrawable"
tools:ignore="ContentDescription" />
<TextView
android:id="#+id/recycler_text"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="29dp"
android:layout_weight="1.5"
android:gravity="center"
android:text="Browse Items"
android:textAlignment="center"
android:textSize="24sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
If you want to get the click event of recyclerview item in HomeFragment ,
Interface It's a good choice
//RecycleAdapter
private RecyclerViewListener recyclerViewListener
public void setRecyclerViewListener(RecyclerViewListener recyclerViewListener){
this.RecyclerViewListener recyclerViewListener ;
}
public Interface RecyclerViewListener{
void onClick(View view);
}
class MyViewHolder extends RecyclerView.ViewHolder{
ImageView imageView;
TextView recyclertext;
public MyViewHolder(#NonNull View itemView) {
super(itemView);
recyclertext = itemView.findViewById(R.id.recycler_text);
recyclertext .setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(recyclerViewListener !=null)recyclerViewListener.onClick(v)
}
});
}
//HomeFragment
recycleAdapter.setRecyclerViewListener(new RecyclerViewListener{
#Override
public void onClick(View v) {
//todo
}
})
Create Interface Class in your Project
public interface ItemClick {
public void onClick(IconsModel IconsModel,int pos);
}
Interface class call your recyclerAdapter
public class RecycleAdapter extends RecyclerView.Adapter<RecycleAdapter.MyViewHolder> {
Context context;
List<IconsModel> iconsList;
ItemClick click;
public TokensListAdapter(Context context, List<IconsModel> iconsList, ItemClick click) {
this.context = context;
this.tokensModelList = tokensModelList;
this.click = click;
}
#NonNull
#Override
public TokensListAdapter.ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View view = inflater.inflate(R.layout.R.layout.recycler_row_items,parent,false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull TokensListAdapter.ViewHolder holder, int position) {
IconsModel iconModel = iconsList.get(position);
holder.imageView.setImageResource(iconModel.getImageid());
holder.recyclertext.setText(iconModel.getIconName());
holder.itemView.setOnClickListener(v -> {
click.onClick(iconModel,position);
});
}
#Override
public int getItemCount() {
return iconsList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
ImageView imageView;
TextView recyclertext;
public ViewHolder(#NonNull View itemView) {
super(itemView);
imageView = itemView.findViewById(R.id.recycler_image);
recyclertext = itemView.findViewById(R.id.recycler_text);
}
}
}
Interface Class implement Your Fragment
public class HomeFragment extends Fragment implements ItemClick {
//adapter assign
recycleAdapter = new RecycleAdapter(getContext,list,this);
override method import your fragment
#Override
public void onClick(ItemCLick click, int pos) {
Toast.makeText(getContext(), "Clicked" + pos, Toast.LENGTH_SHORT).show();
}

tindercard library not working after one swipe

i have to implement swipe card functionality and after a single swipe, when we move for second swipe it stops working
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".All_Modules.FindMatch.Search">
<com.tablefortwo.Views.tindercard.SwipeFlingAdapterView
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/trans_grey"
app:rotation_degrees="15.5" />
</androidx.constraintlayout.widget.ConstraintLayout>
this is code for activity
public class Search extends BaseActivity {
#BindView(R.id.frame)
SwipeFlingAdapterView frame;
SwipeFlingAdapterView.onFlingListener onFlingListener;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
ButterKnife.bind(this);
onFlingListener = new SwipeFlingAdapterView.onFlingListener() {
#Override
public void removeFirstObjectInAdapter() {
}
#Override
public void onLeftCardExit(Object dataObject) {
FlingCardListener.FlingListener flingListener = frame.getFlingListener();
flingListener.onCardExited();
}
#Override
public void onRightCardExit(Object dataObject) {
}
#Override
public void onAdapterAboutToEmpty(int itemsInAdapter) {
}
#Override
public void onScroll(float scrollProgressPercent) {
}
};
frame.setFlingListener(onFlingListener);
SearchAdapter adapter = new SearchAdapter(mContext);
frame.setAdapter(adapter);
}
}
this is the code for adapter
public class SearchAdapter extends BaseAdapter {
Context ctx;
public SearchAdapter(Context ctx) {
this.ctx = ctx;
}
#Override
public int getCount() {
return 20;
}
#Override
public Object getItem(int position) {
return position;
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.card_item, parent, false);
}
return convertView;
}
}
count is static at 20 ...but after first count it stops and doesnot swipe
further and i need to make it swipe upto the count 20 just like tinder app functionality
Please remove data from your list as well after swiping the card and then notify your adapter, it will work fine then.

Firestore recycler adapter not fetching document names

I'm trying fetch all documents using FirestoreRecyclerAdapter here if there are 7 documents the RecyclerView items successfully populates with 7 items but here problem is the items which are having a text view are not getting populated with document names. Please take a look at my source code:
FriendsResponse Class:
#IgnoreExtraProperties
public class FriendsResponse {
FirebaseFirestore db;
public String getTable1() {
return Table1;
}
public void setTable1(String table1) {
Table1 = table1;
}
private String Table1;
public FriendsResponse() {
}
public FriendsResponse(String Table1) {
this.Table1 = Table1;
}
}
TableList Fragment where recyclerview is initialized:
public class TableListFragment extends Fragment{
private FirebaseFirestore db;
private FirestoreRecyclerAdapter adapter;
String documentnm;
RecyclerView recyclerView;
FloatingActionButton addt;
private StaggeredGridLayoutManager _sGridLayoutManager;
public static TableListFragment newInstance() {
TableListFragment fragment = new TableListFragment();
return fragment;
}
public TableListFragment() {
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_tablelist, container, false);
recyclerView = view.findViewById(R.id.rectab);
addt=view.findViewById(R.id.addtab);
init();
getFriendList();
addt.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
return view;
}
private void init(){
_sGridLayoutManager = new StaggeredGridLayoutManager(3,
StaggeredGridLayoutManager.VERTICAL);
recyclerView.setLayoutManager(_sGridLayoutManager);
db = FirebaseFirestore.getInstance();
}
private void getFriendList(){
Query query = db.collection("Order");
FirestoreRecyclerOptions<FriendsResponse> response = new FirestoreRecyclerOptions.Builder<FriendsResponse>()
.setQuery(query, FriendsResponse.class)
.build();
adapter = new FirestoreRecyclerAdapter<FriendsResponse, FriendsHolder>(response) {
#Override
public void onBindViewHolder(FriendsHolder holder, int position, FriendsResponse model) {
holder.exname.setText(model.getTable1());
holder.itemView.setOnClickListener(v -> {
Snackbar.make(recyclerView, model.getTable1(), Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
});
}
#Override
public FriendsHolder onCreateViewHolder(ViewGroup group, int i) {
View view = LayoutInflater.from(group.getContext())
.inflate(R.layout.list_item, group, false);
return new FriendsHolder(view);
}
#Override
public void onError(FirebaseFirestoreException e) {
Log.e("error", e.getMessage());
}
};
adapter.notifyDataSetChanged();
recyclerView.setAdapter(adapter);
}
public class FriendsHolder extends RecyclerView.ViewHolder {
TextView exname;
public FriendsHolder(View itemView) {
super(itemView);
exname= itemView.findViewById(R.id.topicname);
}
}
#Override
public void onStart() {
super.onStart();
adapter.startListening();
}
#Override
public void onStop() {
super.onStop();
adapter.stopListening();
}
#Override
public void onAttach(Context context) {
super.onAttach(context);
}
#Override
public void onDetach() {
super.onDetach();
}
}
This is the code of list_item:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView android:id="#+id/cardvw"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="6dp"
card_view:cardElevation="3dp"
card_view:cardUseCompatPadding="true"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:card_view="http://schemas.android.com/apk/res-auto">
<LinearLayout android:orientation="vertical" android:padding="5dp" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="5dp">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/topiclogo"
android:layout_width="match_parent"
android:layout_gravity="center"
android:src="#drawable/table"
android:layout_height="wrap_content"
/>
<TextView android:textSize="15sp"
android:textStyle="bold"
android:textAlignment="center"
android:textColor="#ffffa200"
android:id="#+id/topicname"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.CardView>
As I understand, you want to set the id of the document to that TextView. So because those names are actually documents ids, you should use the following lines of code inside onBindViewHolder() method:
String id = getSnapshots().getSnapshot(position).getId();
holder.exname.setText(id);
The POJO class that you are using is useful when getting the properties of the documents, not to get the document ids.

How to arrange the data on RecycleView in android?

I would like to use RecycleView for displaying my array of data.
This is my Adapater class which is setting data on view.
public class DataAdapter extends RecyclerView.Adapter<DataAdapter.MyViewHolder>{
private Context context;
private List<Pojo> dataList;
public DataAdapter(Context context, List<Pojo> dataList) {
this.context = context;
this.dataList = dataList;
}
#Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_main,parent,false);
return new MyViewHolder(view);
}
#Override
public void onBindViewHolder(MyViewHolder holder, int position) {
holder.categoryTV.setText(dataList.get(position).getGameName());
}
#Override
public int getItemCount() {
return dataList.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder{
public TextView categoryTV;
public MyViewHolder(View itemView) {
super(itemView);
categoryTV = (TextView) itemView.findViewById(R.id.text);
}
}
}
This is my activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:id="#+id/rellayout"
tools:context="com.acknotech.kiran.retrofit_second.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/text"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
This is MainActivity..
public class MainActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private DataAdapter dataAdapter;
private List<Pojo> dataArrayList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initViews();
}
private void initViews(){
recyclerView=(RecyclerView) findViewById(R.id.my_recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
loadJSON();
}
private void loadJSON(){
dataArrayList = new ArrayList<>();
Retrofit retrofit=new Retrofit.Builder().baseUrl("my url").addConverterFactory(GsonConverterFactory.create()).build();
AllGamesAPI requestInterface=retrofit.create(AllGamesAPI.class);
Call<List<Pojo>> call= requestInterface.getJSON();
call.enqueue(new Callback<List<Pojo>>() {
#Override
public void onResponse(Call<List<Pojo>> call, Response<List<Pojo>> response) {
dataArrayList = response.body();
dataAdapter=new DataAdapter(getApplicationContext(),dataArrayList);
recyclerView.setAdapter(dataAdapter);
}
#Override
public void onFailure(Call<List<Pojo>> call, Throwable t) {
Log.e("Error",t.getMessage());
}
});
}
}
When i try to execute it always printing only one item at a time but in dataList i have 11 items.
How to use RecyclerView to get all items in a page?
Thanks & Regards
You shouldn't inflate the activities layout in onCreateViewHolder, but instead inflate a layout for only one item (e.g. android.R.layout.simple_list_item_1, or a custom one). This layout should not use match_parent for the height of items.

RecyclerView not populating on fragment

I have been trying to figure this problem out for quite a while now, but i just can't figure out what the problem is. The aim is to make a request to Songkick api (which is json), which will return the upcoming events of artist and populate it on the the fragment. The request works fine, but it doesn't come on the screen using recyclerView.
This is my xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.artispot.fragments.FragmentEvents">
<android.support.v7.widget.RecyclerView
android:id="#+id/List"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
This is the Adapter:
public class AdapterEvents extends RecyclerView.Adapter<AdapterEvents.ViewHolderEvents> {
private LayoutInflater layoutInflater;
private String cls = "TAG";
private ArrayList<Events> listEvents = new ArrayList<>();
public AdapterEvents(Context context){
layoutInflater = LayoutInflater.from(context);
}
public void setListEvents(ArrayList<Events> listEvents){
this.listEvents = listEvents;
notifyItemRangeChanged(0,listEvents.size());
}
#Override
public ViewHolderEvents onCreateViewHolder(ViewGroup parent, int viewType) {
View view = layoutInflater.inflate(R.layout.custom_events,parent,false);
ViewHolderEvents viewHolder =new ViewHolderEvents(view);
return viewHolder;
}
//create an object for each textview
#Override
public void onBindViewHolder(ViewHolderEvents holder, int position) {
Events currentEvent = listEvents.get(position);
holder.DateTextView.setText(currentEvent.getStartDate());
// + "--"+ currentEvent.getEndDate()
holder.displayName.setText(currentEvent.getDisplayName());
holder.Venue.setText(currentEvent.getVenue());
}
#Override
public int getItemCount() {
return listEvents.size();
}
static class ViewHolderEvents extends RecyclerView.ViewHolder{
private TextView DateTextView;
private TextView displayName;
private TextView Venue;
public ViewHolderEvents(View itemView){
super(itemView);
DateTextView = (TextView) itemView.findViewById(R.id.DateTextView);
displayName = (TextView) itemView.findViewById(R.id.displayName);
Venue = (TextView) itemView.findViewById(R.id.Venue);
}
}
}
and this part is from my fragment class:
public void sendRequest(){
// Formulate the request and handle the response.
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET,
getRequestUrl(),(String)null,
new Response.Listener<JSONObject>() {
#Override
public void onResponse( JSONObject response) {
listEvents= parseJSONResponse(response);
adapterEvents.setListEvents(listEvents);
}
},
new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
// Handle error
}
});
requestQueue.add(request);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_events, container,false);
recyclerView = (RecyclerView)view.findViewById(R.id.List);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
adapterEvents = new AdapterEvents(getActivity());
recyclerView.setAdapter(adapterEvents);
return view;
}
I have been on this for about a few days, and it's sort of frustrating because it's my project that is due in a week time. Any sort of help will be much appreciated. Thanks in advance.

Categories