I have created an application and data of user is loaded via firebase recycler adapter. It have data of users and each user have a link in their profile which redirect to a webpage. Everything is working fine the user is redirected to the webpage via the default browser. My question is how can I restrict the app to open the links/urls within itself. I don't want the links to be opened in the default browser. Below is my code
MyViewholder
class MyViewHolder extends RecyclerView.ViewHolder {
TextView geglink, userName, userAbout;
View v;
public MyViewHolder(#NonNull #NotNull View itemView) {
super(itemView);
geglink = (TextView) itemView.findViewById(R.id.rcvGigLink);
userName = (TextView) itemView.findViewById(R.id.rcvName);
userAbout = (TextView) itemView.findViewById(R.id.rcvAbout);
v = itemView;
DashboardActivity
RecyclerView recyclerView;
FirebaseRecyclerOptions<ModelClass> options;
FirebaseRecyclerAdapter<ModelClass, MyViewHolder> adapter;
DatabaseReference dRef;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard);
dRef = FirebaseDatabase.getInstance().getReference().child("Users");
recyclerView = findViewById(R.id.dashboardRCV);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
LoadData();
}
private void LoadData() {
options = new FirebaseRecyclerOptions.Builder<ModelClass>()
.setQuery(dRef, ModelClass.class)
.build();
adapter = new FirebaseRecyclerAdapter<ModelClass, MyViewHolder>(options) {
#Override
protected void onBindViewHolder(#NonNull MyViewHolder holder, int position, #NonNull ModelClass model) {
holder.geglink.setText(model.getGig());
holder.userName.setText(model.getName());
holder.userAbout.setText(model.getAbout());
holder.v.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String url = model.getGig();
if (!url.startsWith("http://") && !url.startsWith("https://")){
url = "https://" + url;
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);
}
}
});
}
#NonNull
#Override
public MyViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recyclerview_layout, parent, false);
return new MyViewHolder(view);
}
};
adapter.startListening();
recyclerView.setAdapter(adapter);
}
}
ModelClass
public class ModelClass {
String gig, name, about;
public String getGig() {
return gig;
}
public void setGig(String gig) {
this.gig = gig;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAbout() {
return about;
}
public void setAbout(String about) {
this.about = about;
}
public ModelClass(String gig, String name, String about) {
this.gig = gig;
this.name = name;
this.about = about;
}
public ModelClass() {
}
}
Thanks in advance
Related
I made an app that fetches and stores data from the Android application to the Firebase, and I made activity that includes RecyclerView in which the data is displayed, but the problem is that when I click on any record in RecyclerView, I want to open another screen that contains the same data that was pressed, and I Try the code mentioned below, but when you press on RecyclerView, the application stops (and I think the problem is in the process of transferring data when I click on the record)
Please help me to solve the problem
The class code
public class EMP_INFO implements Serializable {
private String Id;
private String Name;
private String City;
public EMP_INFO() {
}
public String getEmployeeID() {
return Id;
}
public void setEmployeeID(String ID) {
this.Id = ID;
}
public String getEmployeeName() {
return Name;
}
public void setEmployeeName(String Name) {
this.Name = Name;
}
public String getEmployeeCity() {
return City;
}
public void setEmployeeCity(String City) {
this.City = City;
}
}
The adapter code
public class EMP_INFO_Adapter extends FirebaseRecyclerAdapter<EMP_INFO, EMP_INFO_Adapter.personsViewholder> {
public EMP_INFO_Adapter(#NonNull FirebaseRecyclerOptions<EMP_INFO> options)
{
super(options);
}
#Override
protected void
onBindViewHolder(#NonNull personsViewholder holder, int position, #NonNull EMP_INFO model)
{
holder.F_ID.setText(model.getEmployeeID());
holder.F_name.setText(model.getEmployeeName());
holder.F_city.setText(model.getEmployeeCity());
Intent intent = new Intent(context, FireBase_Save_data_1.class);
intent.putExtra("FB_id1", String.valueOf(model.getEmployeeID()));
intent.putExtra("FB_name1", String.valueOf(model.getEmployeeName()));
intent.putExtra("FB_city1", String.valueOf(model.getEmployeeCity()));
activity.startActivityForResult(intent, 1);
}
#NonNull
#Override
public personsViewholder
onCreateViewHolder(#NonNull ViewGroup parent, int viewType)
{
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fire_base_my_row, parent, false);
return new EMP_INFO_Adapter.personsViewholder(view);
}
class personsViewholder extends RecyclerView.ViewHolder { TextView F_ID, F_name, F_city;
public personsViewholder(#NonNull View itemView)
{
super(itemView);
F_ID = itemView.findViewById(R.id.F_ID);
F_name = itemView.findViewById(R.id.F_name);
F_city = itemView.findViewById(R.id.F_city);
}
}
}
The RecyclerView activity code
public class FireBase_Recyclerview_2 extends AppCompatActivity {
private RecyclerView recyclerView;
Button add_button;
EMP_INFO_Adapter adapter;
//EMP_INFO_Adapter_3 adapter;
DatabaseReference mbase;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fire_base_recyclerview_2);
add_button = findViewById(R.id.add_button);
recyclerView = findViewById(R.id.recycler1);
// To display the Recycler view linearly
recyclerView.setLayoutManager(new LinearLayoutManager(this));
mbase = FirebaseDatabase.getInstance().getReference("EmployeeInfo") ;
FirebaseRecyclerOptions<EMP_INFO> options = new FirebaseRecyclerOptions.Builder<EMP_INFO>()
.setQuery(mbase, EMP_INFO.class).build();
adapter = new EMP_INFO_Adapter(options);
//adapter = new EMP_INFO_Adapter_3(options);
recyclerView.setAdapter(adapter);
add_button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(FireBase_Recyclerview_2.this, FireBase_Save_data_1.class);
startActivity(intent);
}
});
}
#Override protected void onStart()
{
super.onStart();
adapter.startListening();
}
#Override protected void onStop()
{
super.onStop();
adapter.stopListening();
}
}
You may put a click Listener on the item inside your adapter's onBindViewHolder,as shown below.
holder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Context context = v.getContext();
Intent intent = new Intent(context, FireBase_Save_data_1.class);
intent.putExtra("empId", model.getEmployeeID());
intent.putExtra("empName", model.getEmployeeName());
intent.putExtra("empCity", model.getEmployeeCity());
context.startActivity(intent);
}
});
You can't start activity within onBinViewHolder.move that code to viewholder class.
public class EMP_INFO_Adapter extends FirebaseRecyclerAdapter<EMP_INFO, EMP_INFO_Adapter.personsViewholder> {
public EMP_INFO_Adapter(#NonNull FirebaseRecyclerOptions<EMP_INFO> options)
{
super(options);
}
#Override
protected void
onBindViewHolder(#NonNull personsViewholder holder, int position, #NonNull EMP_INFO model)
{
holder.F_ID.setText(model.getEmployeeID());
holder.F_name.setText(model.getEmployeeName());
holder.F_city.setText(model.getEmployeeCity());
}
#NonNull
#Override
public personsViewholder
onCreateViewHolder(#NonNull ViewGroup parent, int viewType)
{
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fire_base_my_row, parent, false);
return new EMP_INFO_Adapter.personsViewholder(view);
}
class personsViewholder extends RecyclerView.ViewHolder implements View.OnClickListener
TextView F_ID, F_name, F_city;
public personsViewholder(#NonNull View itemView)
{
super(itemView);
F_ID = itemView.findViewById(R.id.F_ID);
F_name = itemView.findViewById(R.id.F_name);
F_city = itemView.findViewById(R.id.F_city);
itemView.setOnClickListener(this);
}
#Override
public void onClick(View view) {
int id=getAdapterPosition();
Intent intent = new Intent(context, FireBase_Save_data_1.class);
intent.putExtra("FB_id1", String.valueOf(model.get(id).getEmployeeID()));
intent.putExtra("FB_name1", String.valueOf(model.get(id).getEmployeeName()));
intent.putExtra("FB_city1", String.valueOf(model.get(id).getEmployeeCity()));
activity.startActivityForResult(intent, 1);
}
}
}
}
}
I'm a beginner in android development . i have created an app that display data(image and text ) from Firebase in RecyclerView . everything is working fine , there is also one data (url) and i want when the user will click on any item it will start new activity using Intent and will display this url in a Webview . i have created new activity and set up the WebView in it . i just don't know how to pass the url from firebase to this activity . i was searching for 3 days and i did know that i need to use setOnClickItemListener but i didn't find anything realted to my case . that's why i thought about posting it here .
sorry for my English . thank you
my Firebase data is like this
enter image description here
this is model.java
public class model {
String title, image, description ,url;
public model() {
this.url=url ;
this.title = title;
this.image = image;
this.description = description;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getTitle() {
return title;
}
public String getImage() {
return image;
}
public String getDescription() {
return description;
}
public void setTitle(String title) {
this.title = title;
}
public void setImage(String image) {
this.image = image;
}
public void setDescription(String description) {
this.description = description;
}
}
and this is the RecyclerAdapter.java
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ViewHolder>{
private Context mContext;
private List<model> modelList;
public RecyclerAdapter(Context context, List<model> listData) {
this.modelList = listData;
this.mContext = context;
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view=LayoutInflater.from(parent.getContext()).inflate(R.layout.row,parent,false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
holder.title.setText(modelList.get(position).getTitle());
holder.description.setText((modelList.get(position).getDescription()));
Picasso.get().load(modelList.get(position).getImage()).into(holder.imageView);
}
#Override
public int getItemCount() {
return modelList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView title,description;
ImageView imageView;
public ViewHolder(View itemView){
super(itemView);
title=itemView.findViewById(R.id.Title);
description=itemView.findViewById(R.id.Description);
imageView=itemView.findViewById(R.id.ImageView);
}
}
}
and this is MainActivity.java
public class MainActivity extends AppCompatActivity {
private DatabaseReference reference ;
private StorageReference mStorageRef ;
private RecyclerView recyclerView;
private ArrayList<model> modelList;
private Context mContext = MainActivity.this;
private RecyclerAdapter recyclerAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LinearLayoutManager layoutManager= new LinearLayoutManager(this );
recyclerView=findViewById(R.id.recyclerview);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setHasFixedSize(true);
reference = FirebaseDatabase.getInstance().getReference();
mStorageRef = FirebaseStorage.getInstance().getReference();
modelList = new ArrayList<>();
init();
}
private void init(){
clearAll();
Query query = reference.child("Data");
query.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()){
model rmodel = new model();
rmodel.setImage(snapshot.child("image").getValue().toString());
rmodel.setTitle(snapshot.child("title").getValue().toString());
rmodel.setUrl(snapshot.child("url").getValue().toString());
rmodel.setDescription(snapshot.child("description").getValue().toString());
modelList.add(rmodel);
}
recyclerAdapter = new RecyclerAdapter(mContext , modelList);
recyclerView.setAdapter(recyclerAdapter);
recyclerAdapter.notifyDataSetChanged();
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
});
}
private void clearAll(){
if (modelList !=null){
modelList.clear();
if(recyclerAdapter != null)
recyclerAdapter.notifyDataSetChanged();
}
modelList = new ArrayList<>();
}
}
In the onBindViewHolder method:
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
holder.title.setText(modelList.get(position).getTitle());
holder.description.setText((modelList.get(position).getDescription()));
Picasso.get().load(modelList.get(position).getImage()).into(holder.imageView);
holder.addOnClickListener(new OnClickListener() {
#override
public void onClick(View v) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(modelList.get(position).getUrl()));
startActivity(browserIntent);
}
});
}
This will add an action listener on the holder to open the URL in a browser.
Hi i'm stuck on this part where i have 2 collections first one is users and second one is friends. I want my recyclerview to display my friends on the list with the help of current user because on currentUser other peoples id are stored and i want it to display it on the recyclerview but when it displays it i want to get their information from users where they have their username and email stored.
I want only friends collection ids to display on recyclerview with the help of current user id. Then i want to get values from users collection like their name and email value.
Friends collection
users collection
ADAPTER
public class FriendsAdapter extends FirestoreRecyclerAdapter {
private OnItemClicklistener onItemClicklistener;
public FriendsAdapter(#NonNull FirestoreRecyclerOptions<AllUsers> options) {
super(options);
}
#Override
protected void onBindViewHolder(#NonNull FriendsHolder holder, int position, #NonNull AllUsers model) {
holder.textViewUsername.setText(String.valueOf(model.getName()));
holder.textViewEmail.setText(model.getEmail());
holder.setAvatar(model.getAvatar());
}
#NonNull
#Override
public FriendsHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.all_user_list_display, viewGroup, false);
return new FriendsAdapter.FriendsHolder(view);
}
class FriendsHolder extends RecyclerView.ViewHolder {
TextView textViewUsername;
TextView textViewEmail;
ImageView imageViewAvatar;
public FriendsHolder(#NonNull View itemView) {
super(itemView);
textViewUsername = itemView.findViewById(R.id.all_user_username);
textViewEmail = itemView.findViewById(R.id.all_user_userEmail);
itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
int position = getAdapterPosition();
if (position != RecyclerView.NO_POSITION && onItemClicklistener != null) {
onItemClicklistener.onItemClick(getSnapshots().getSnapshot(position), position);
}
}
});
}
public void setAvatar(String avatar) {
imageViewAvatar = (ImageView) itemView.findViewById(R.id.all_user_profile_image);
Picasso.get().load(avatar).into(imageViewAvatar);
}
}
public interface OnItemClicklistener {
void onItemClick(DocumentSnapshot snapshot, int position);
}
public void setOnItemClickListener(FriendsAdapter.OnItemClicklistener listener) {
onItemClicklistener = listener;
}
FriendListFragment
public class FriendsListFragment extends Fragment {
private FirebaseFirestore db;
private CollectionReference usersCollection;
private CollectionReference friendsCollection;
private DocumentReference friends;
private DocumentReference users;
private FirebaseUser current_user;
private FriendsAdapter adapter;
public SearchView search_friends;
public FriendsListFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_friends, container, false);
current_user = FirebaseAuth.getInstance().getCurrentUser();
//FIREBASE
db = FirebaseFirestore.getInstance();
usersCollection = db.collection("users");
friendsCollection = db.collection("friends");
friends = friendsCollection.document(current_user.getUid());
Query friendQuery = usersCollection;
FirestoreRecyclerOptions<AllUsers> options = new FirestoreRecyclerOptions.Builder<AllUsers>()
.setQuery(friendQuery, AllUsers.class)
.build();
adapter = new FriendsAdapter(options);
RecyclerView recyclerView = view.findViewById(R.id.friendsList);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.setAdapter(adapter);
return view;
}
#Override
public void onStart() {
super.onStart();
adapter.startListening();
}
AllUsersClass
public class AllUsers {
public String name;
public String avatar;
public String email;
public String userId;
public AllUsers() {
}
public AllUsers(String name, String email, String avatar, String userId) {
this.name = name;
this.email = email;
this.avatar = avatar;
this.userId = userId;
}
public String getName() {
return name;
}
public String getAvatar() {
return avatar;
}
public String getEmail() {
return email;
}
public void setAvatar(String avatar) {
this.avatar = avatar;
}
I am trying make an application with 2 screen: MainActivity (login) and CustomerInfoActivity.
Login screen with.
The other screen is used to show customer information (name, phone, image) displayed by recycler view, and a textview to display location update.
Using broadcast receiver and catch the event when the device go to sleep mode/wake up => disable/enable service.
My app crash when I click the Login button to jump to the Recycle view screen and I have no idea how to handle the disable Service requirement.
Please give me some help. Thank you.
DataCustomer.java
public class DataCustomer {
private int image;
private String name;
private int phonenumber;
public DataCustomer(String name, int phonenumber, int image) {
this.image = image;
this.name = name;
this.phonenumber = phonenumber;
}
public int getImage() {
return image;
}
public void setImage(int image) {
this.image = image;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPhonenumber() {
return phonenumber;
}
public void setPhonenumber(int phonenumber) {
this.phonenumber = phonenumber;
}}
CustomerAdapter.java
public class CustomerAdapter extends RecyclerView.Adapter<CustomerAdapter.ViewHolder> {
private ArrayList<DataCustomer> dataCustomers;
private Context context;
public CustomerAdapter(ArrayList<DataCustomer> dataCustomers, Context context) {
this.dataCustomers = dataCustomers;
this.context = context;
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
View itemView = layoutInflater.inflate(R.layout.item_customer,parent,false);
return new ViewHolder(itemView);
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
holder.customer_name.setText(dataCustomers.get(position).getName());
holder.customer_phone.setText(dataCustomers.get(position).getPhonenumber());
holder.customer_image.setImageResource(dataCustomers.get(position).getImage());
}
#Override
public int getItemCount() {
return dataCustomers.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
TextView customer_name;
TextView customer_phone;
ImageView customer_image;
public ViewHolder(View itemView){
super(itemView);
customer_name = (TextView)itemView.findViewById(R.id.customer_name);
customer_phone = (TextView) itemView.findViewById(R.id.customer_phone);
customer_image = (ImageView)itemView.findViewById(R.id.customer_image);
}
}}
CustomerInfoActivity.java
public class CustomerInfoActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.customer_info);
initView();
}
public void initView(){
RecyclerView recyclerView = (RecyclerView)findViewById(R.id.customer_items);
recyclerView.setHasFixedSize(true);
LinearLayoutManager layoutManager = new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false);
recyclerView.setLayoutManager(layoutManager);
ArrayList<DataCustomer> arrayList = new ArrayList<>();
arrayList.add(new DataCustomer("A",12,R.drawable.A));
arrayList.add(new DataCustomer("B",34,R.drawable.B));
arrayList.add(new DataCustomer("C",56,R.drawable.C));
arrayList.add(new DataCustomer("D",78,R.drawable.D));
CustomerAdapter customerAdapter = new CustomerAdapter(arrayList, getApplicationContext());
recyclerView.setAdapter(customerAdapter);
}}
MainActivity.java
public class MainActivity extends AppCompatActivity {
private static EditText username;
private static EditText password;
private static CheckBox rememberpassword;
private static Button loginbutton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loginButton();
}
public void loginButton(){
username = (EditText)findViewById(R.id.editText_username);
password = (EditText)findViewById(R.id.editText_password);
rememberpassword = (CheckBox)findViewById(R.id.checkBox_rememberpassword);
loginbutton = (Button)findViewById(R.id.button_login);
loginbutton.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
if(username.getText().toString().equals("user") &&
password.getText().toString().equals("pass") ) {
Intent intent = new Intent("com.assignment.assignment2_v2.CustomerInfoActivity");
startActivity(intent);
}
}
}
);
}
}
Crash probably could be fixed by switching for implicit Intent to explicit one:
Intent intent = new Intent(MainActivity.this, CustomerInfoActivity.class);
startActivity(intent);
Try this one. Also could you add your crash logs if this will not help?
I am trying to fetch data from my Parse database and display it into a RecyclerView. From my knowledge I cannot see what I have done wrong and when I run the app not errors occur, and when opening this very fragment the app doesn't crash just shows a blank screen.
Any idea what is the problem?
Businesses
package zafir.com.app;
import com.parse.ParseClassName;
import com.parse.ParseObject;
#ParseClassName("Businesses")
public class Businesses extends ParseObject
{
private String Name;
public String getName()
{
return getString("Name");
}
public void setName(String name)
{
put("Name", name);
}
public String getCategory()
{
return getString("Category");
}
public void setCategory(String category)
{
put("Category", category);
}
public String getEmail()
{
return getString("Email");
}
public void setEmail(String email)
{
put("Email", email);
}
public String getLocation()
{
return getString("Location");
}
public void setLocation(String location)
{
put("Location", location);
}
public String getPhone()
{
return getString("Phone");
}
public void setPhone(String phone)
{
put("Phone", phone);
}
public String getWebsite()
{
return getString("Website");
}
public void setWebsite(String website)
{
put("Website", website);
}
}
RecyclerAdapter
public static class ViewHolder extends RecyclerView.ViewHolder
{
public TextView zName;
public TextView zPhone;
public TextView zEmail;
public TextView zWebsite;
public TextView zLocation;
public TextView zCategory;
public ViewHolder(View itemView)
{
super(itemView);
zName = (TextView) itemView.findViewById(R.id.name);
zPhone = (TextView) itemView.findViewById(R.id.phone);
zEmail = (TextView) itemView.findViewById(R.id.email);
zWebsite = (TextView) itemView.findViewById(R.id.website);
zLocation = (TextView) itemView.findViewById(R.id.location);
zCategory = (TextView) itemView.findViewById(R.id.category);
}
}
public RecyclerAdapter(Context context,List<Businesses> data)
{
inflater=LayoutInflater.from(context);
this.data= data;
}
#Override
public RecyclerAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
Context context = parent.getContext();
LayoutInflater inflater = LayoutInflater.from(context);
View recView = inflater.inflate(R.layout.recycler_layout, parent, false);
ViewHolder ViewHolder = new ViewHolder(recView);
return ViewHolder;
}
#Override
public void onBindViewHolder(RecyclerAdapter.ViewHolder viewHolder, int position)
{
Businesses businesses = data.get(position);
TextView name = viewHolder.zName;
name.setText(businesses.getName());
TextView phone = viewHolder.zPhone;
phone.setText(businesses.getPhone());
TextView email = viewHolder.zEmail;
email.setText(businesses.getEmail());
TextView website = viewHolder.zWebsite;
website.setText(businesses.getWebsite());
TextView location = viewHolder.zLocation;
location.setText(businesses.getLocation());
TextView category = viewHolder.zCategory;
category.setText(businesses.getCategory());
}
#Override
public int getItemCount()
{
return data.size();
}
}
Categories(Fragment)
public class Categories extends Fragment
{
List<Businesses> data = new ArrayList<>();
private RecyclerView zRecyclerView;
private RecyclerAdapter zAdapter;
private RecyclerView.LayoutManager zLayoutManager;
public Categories()
{
// Required empty public constructor
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable
Bundle savedInstanceState)
{
View rootView = inflater.inflate(R.layout.fragment_categories,container, false);
zRecyclerView = (RecyclerView) rootView.findViewById(R.id.recview_categories);
zRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
getData();
return super.onCreateView(inflater, container, savedInstanceState);
}
public void getData()
{
final List<Businesses> data = new ArrayList<>();
ParseQuery<Businesses> query = new ParseQuery<>("Businesses");
query.findInBackground(new FindCallback<Businesses>()
{
#Override
public void done(List<Businesses> list, ParseException e)
{
if(e == null)
{
for(Businesses businesses : list)
{
Businesses bizList = new Businesses();
bizList.setNames(businesses.getNames());
bizList.setPhone(businesses.getPhone());
bizList.setEmail(businesses.getEmail());
bizList.setWebsite(businesses.getWebsite());
bizList.setLocation(businesses.getLocation());
bizList.setCategory(businesses.getCategory());
data.add(bizList);
}
zAdapter = new RecyclerAdapter(getActivity(), data);
zRecyclerView.setAdapter(zAdapter);
}
}
});
}
}
Everything looks good. You just have to call notifyDataSetChanged() on zAdapter whenever you are changing the data. So change your code like this:
zAdapter = new RecyclerAdapter(getActivity(), data);
zRecyclerView.setAdapter(zAdapter);
zAdapter.notifyDataSetChanged();