This is SearchActivity.java
public class SearchActivity extends AppCompatActivity
{
/*UI*/
private EditText mSearchText;
private Button mSearchBtn;
private Toolbar mSearchToolbar;
private FragmentPagerAdapter mPagerAdapter;
private ViewPager mViewPager;
private String value;
private TextWatcher tw;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
mSearchText = (EditText)findViewById(R.id.activity_search_search_text);
mSearchBtn = (Button)findViewById(R.id.activity_search_search_btn);
mSearchToolbar = (Toolbar)findViewById(R.id.activity_search_toolbar);
setSupportActionBar(mSearchToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(null);
mSearchBtn.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
value = mSearchText.getText().toString();
Toast.makeText(SearchActivity.this, "value test 1: " + value, Toast.LENGTH_LONG).show();
searchText(value);
}
});
}
private void searchText(final String value)
{
Toast.makeText(SearchActivity.this, "value test 2: " + value, Toast.LENGTH_LONG).show();
mPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager())
{
private final Fragment[] mFragments = new Fragment[]
{
new FragmentSearch(value)
};
#Override
public Fragment getItem(int position)
{
return mFragments[position];
}
#Override
public int getCount()
{
return mFragments.length;
}
};
mViewPager = (ViewPager) findViewById(R.id.activity_search_view_pager);
mViewPager.setAdapter(mPagerAdapter);
}
}
This is FragmentSearch.java
public class FragmentSearch extends MainFragment
{
public String value;
public FragmentSearch(String value)
{
this.value = value;
}
#Override
public Query getQuery(DatabaseReference databaseReference)
{
Toast.makeText(getActivity().this, "value test 3: " + value, Toast.LENGTH_LONG).show();
Query postsQuery = databaseReference.child("Post").orderByChild("title").equalTo(value);
return postsQuery;
}
}
This is MainFragment.java
public abstract class MainFragment extends Fragment
{
private DatabaseReference mDatabase;
private FirebaseRecyclerAdapter<Post, PostViewHolder> mAdapter;
private RecyclerView mRecycler;
private LinearLayoutManager mManager;
public MainFragment()
{
}
#Override
public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
super.onCreateView(inflater, container, savedInstanceState);
View rootView = inflater.inflate(R.layout.fragment_all_posts, container, false);
mDatabase = FirebaseDatabase.getInstance().getReference();
mRecycler = (RecyclerView)rootView.findViewById(R.id.messages_list);
mRecycler.setHasFixedSize(true);
return rootView;
}
#Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
mManager = new LinearLayoutManager(getActivity());
mManager.setReverseLayout(true);
mManager.setStackFromEnd(true);
mRecycler.setLayoutManager(mManager);
Query postsQuery = getQuery(mDatabase);
mAdapter = new FirebaseRecyclerAdapter<Post, PostViewHolder>(Post.class, R.layout.item_post,
PostViewHolder.class, postsQuery)
{
#Override
protected void populateViewHolder(final PostViewHolder viewHolder, final Post model, final int position)
{
final DatabaseReference postRef = getRef(position);
final String postKey = postRef.getKey();
viewHolder.itemView.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
// Intent intent = new Intent(getActivity(), PostDetailActivity.class);
// intent.putExtra(PostDetailActivity.EXTRA_POST_KEY, postKey);
// startActivity(intent);
}
});
if(model.stars.containsKey(getUid()))
{
viewHolder.starView.setImageResource(R.drawable.ic_toggle_star_24);
}
else
{
viewHolder.starView.setImageResource(R.drawable.ic_toggle_star_outline_24);
}
viewHolder.bindToPost(model, new View.OnClickListener()
{
#Override
public void onClick(View starView)
{
DatabaseReference globalPostRef = mDatabase.child("Post").child(postRef.getKey());
DatabaseReference userPostRef = mDatabase.child("UserPost").child(model.uid).child(postRef.getKey());
onStarClicked(globalPostRef);
onStarClicked(userPostRef);
}
});
}
};
mRecycler.setAdapter(mAdapter);
}
private void onStarClicked(DatabaseReference postRef) {
postRef.runTransaction(new Transaction.Handler() {
#Override
public Transaction.Result doTransaction(MutableData mutableData) {
Post p = mutableData.getValue(Post.class);
if (p == null) {
return Transaction.success(mutableData);
}
if (p.stars.containsKey(getUid())) {
// Unstar the post and remove self from stars
p.starCount = p.starCount - 1;
p.stars.remove(getUid());
} else {
// Star the post and add self to stars
p.starCount = p.starCount + 1;
p.stars.put(getUid(), true);
}
// Set value and report transaction success
mutableData.setValue(p);
return Transaction.success(mutableData);
}
#Override
public void onComplete(DatabaseError databaseError, boolean b,
DataSnapshot dataSnapshot) {
}
});
}
#Override
public void onDestroy()
{
super.onDestroy();
if (mAdapter != null)
{
mAdapter.cleanup();
}
}
public String getUid()
{
return FirebaseAuth.getInstance().getCurrentUser().getUid();
}
public abstract Query getQuery(DatabaseReference databaseReference);
}
This is PostViewHolder.java
public class PostViewHolder extends RecyclerView.ViewHolder
{
public TextView titleView;
public TextView authorView;
public ImageView starView;
public TextView numStarsView;
public TextView bodyView;
public PostViewHolder(View itemView)
{
super(itemView);
titleView = (TextView) itemView.findViewById(R.id.post_title);
authorView = (TextView) itemView.findViewById(R.id.post_author);
starView = (ImageView) itemView.findViewById(R.id.star);
numStarsView = (TextView) itemView.findViewById(R.id.post_num_stars);
bodyView = (TextView) itemView.findViewById(R.id.post_body);
}
public void bindToPost(Post post, View.OnClickListener starClickListener)
{
titleView.setText(post.title);
authorView.setText(post.author);
numStarsView.setText(String.valueOf(post.starCount));
bodyView.setText(post.body);
starView.setOnClickListener(starClickListener);
}
}
This is Post.java
#IgnoreExtraProperties
public class Post
{
public String uid;
public String author;
public String title;
public String body;
public int starCount = 0;
public String type;
public Map<String, Boolean> stars = new HashMap<>();
public Post()
{
}
public Post(String uid, String author, String title, String body, String type)
{
this.uid = uid;
this.author = author;
this.title = title;
this.body = body;
this.type = type;
}
#Exclude
public Map<String, Object> toMap()
{
HashMap<String, Object> result = new HashMap<>();
result.put("uid", uid);
result.put("author", author);
result.put("title", title);
result.put("body", body);
result.put("starCount", starCount);
result.put("stars", stars);
result.put("type", type);
return result;
}
}
Thank you so much for reading. I created a program to search title of the posts. When I type title in the EditText then press Search button, my toast1 test, toast2 test, and toast3 test give correct and same value and it successfully lists what I want with Query. But the problem is that when I type different text in EditText after deleting the previous text then press enter, toast3 test(in FragmentSearch.java) stays the same and does not change value. So, it just gives the previous result, not changed result. Can anyone assist me with this? Thank you!
The problem is that you only change the value on the FragmentSearch constructor. And this constructor is only called once, and not when you press Enter.
You should change your getQuery method to have this value as a parameter.
On your MainFragment.java:
public abstract Query getQuery(DatabaseReference databaseReference, String value);
On your FragmentSearch.java:
#Override
public Query getQuery(DatabaseReference databaseReference, String value)
{
this.value = value;
Toast.makeText(getActivity().this, "value test 3: " + value, Toast.LENGTH_LONG).show();
Query postsQuery = databaseReference.child("Post").orderByChild("title").equalTo(value);
return postsQuery;
}
Related
This is the API
INPUT:
center_id:4
tabID:952888062222222
patient_search: 98
OUTPUT:
{
"status": true,
"result": [
{
"patient_id": "3",
"gen_patient_id": "pmhsola00003",
"first_name": "Sama",
"last_name": "Patil",
"p_mobile": "2398322323",
"aadhaar_number": "4561221211212",
"center_id": "4"
}
],
"message": "Patient searched successfully!"
}
Model Class
public class SearchModel {
public SearchModel(String patient_id, String gen_patient_id, String first_name, String last_name, String p_mobile, String aadhaar_number, String center_id) {
this.patient_id = patient_id;
this.gen_patient_id = gen_patient_id;
this.first_name = first_name;
this.last_name = last_name;
this.p_mobile = p_mobile;
this.aadhaar_number = aadhaar_number;
this.center_id = center_id;
}
private String patient_id;
public String getPatientId() { return this.patient_id; }
public void setPatientId(String patient_id) { this.patient_id = patient_id; }
private String gen_patient_id;
public String getGenPatientId() { return this.gen_patient_id; }
public void setGenPatientId(String gen_patient_id) { this.gen_patient_id = gen_patient_id; }
private String first_name;
public String getFirstName() { return this.first_name; }
public void setFirstName(String first_name) { this.first_name = first_name; }
private String last_name;
public String getLastName() { return this.last_name; }
public void setLastName(String last_name) { this.last_name = last_name; }
private String p_mobile;
public String getPMobile() { return this.p_mobile; }
public void setPMobile(String p_mobile) { this.p_mobile = p_mobile; }
private String aadhaar_number;
public String getAadhaarNumber() { return this.aadhaar_number; }
public void setAadhaarNumber(String aadhaar_number) { this.aadhaar_number = aadhaar_number; }
private String center_id;
public String getCenterId() { return this.center_id; }
public void setCenterId(String center_id) { this.center_id = center_id; }
#Override
public String toString()
{
return "ClassPojo [first_name = "+first_name+", aadhaar_number = "+aadhaar_number+", last_name = "+last_name+", patient_id = "+patient_id+", center_id = "+center_id+", p_mobile = "+p_mobile+", gen_patient_id = "+gen_patient_id+"]";
}
}
Result Model Class
public class Result {
private SearchModel[] result;
public SearchModel[] getResult() {
return result;
}
public void setResult(SearchModel[] result) {
this.result = result;
}
}
My Recycler Adapter
public class PatientSearchAdapter extends
RecyclerView.Adapter<PatientSearchAdapter.ViewHolder> {
private ArrayList<SearchModel> searchList;
private Context context;
public PatientSearchAdapter(ArrayList<SearchModel> searchList){
this.searchList = searchList;
}
#Override
public PatientSearchAdapter.ViewHolder onCreateViewHolder(final ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.search_list_row_new,parent,false);
PatientSearchAdapter.ViewHolder viewHolder = new PatientSearchAdapter.ViewHolder(view);
return viewHolder;
}
#Override
public void onBindViewHolder(PatientSearchAdapter.ViewHolder holder, final int position) {
holder.p_name_first.setText( (searchList.get(position).getFirstName()).substring(0,1).toUpperCase() + (searchList.get(position).getFirstName()).substring(1));
holder.p_name_last.setText( (searchList.get(position).getLastName()).substring(0,1).toUpperCase() + (searchList.get(position).getLastName()).substring(1));
holder.p_mobile.setText(searchList.get(position).getPMobile());
holder.p_Id.setText(searchList.get(position).getGenPatientId().toUpperCase());
holder.view_history.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Context context = v.getContext();
Intent intent = new Intent(context, ViewPatientActivity.class);
context.startActivity(intent);
}
});
holder.take_test.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Context context = v.getContext();
Intent intent = new Intent(context, HealthServicesActivity.class);
context.startActivity(intent);
}
});
}
#Override
public int getItemCount() {
return searchList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView p_name_first,p_mobile,p_Id,p_name_last;
Button take_test;
TextView view_history;
public ViewHolder(View v) {
super(v);
p_name_first = (TextView) v.findViewById(R.id.ppatient_name);
p_name_last = (TextView) v.findViewById(R.id.ppatient_last_name);
p_mobile = (TextView) v.findViewById(R.id.pmobile_number);
p_Id=(TextView) v.findViewById(R.id.pp_id);
view_history=(TextView) v.findViewById(R.id.pview_text_1);
take_test=(Button) v.findViewById(R.id.ptake_test_button);
}
}
}
My Fragment
public class PatientListFragment extends Fragment implements
View.OnClickListener {
View view;
#BindView(R.id.search_text)
EditText searchText;
#BindView(R.id.item_search_click)
ImageButton saerchButton;
private ProgressBar progressBar;
Api webService = ServiceGenerator.getApi();
SharePreferenceManager<LoginModel> sharePreferenceManager;
private PatientSearchAdapter mSearchAdapter;
#BindView(R.id.recycler_patient_search_list)
RecyclerView recyclerViewOnSearch;
ArrayList<SearchModel> searchList = new ArrayList<SearchModel>();
public PatientListFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
view= inflater.inflate(R.layout.fragment_patient_list, container, false);
ButterKnife.bind(this,view);
sharePreferenceManager = new SharePreferenceManager<>(getActivity());
progressBar =(ProgressBar) view.findViewById(R.id.progress_bar);
/* progressDialog = new ProgressDialog(getActivity());
progressDialog.setMessage("Please Wait...");
progressDialog.setCanceledOnTouchOutside(false);*/
EditText searchView = (EditText) view.findViewById(R.id.search_text);
initialViewsForSearch();
return view;
}
private void initialViewsForSearch() {
recyclerViewOnSearch.setHasFixedSize(true);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
recyclerViewOnSearch.setLayoutManager(layoutManager);
#Override
public void onClick(View v) {
if (NetworkUtils.isNetworkAvailableToastIfNot(getActivity())) {
getPayientSearchListOnline(
sharePreferenceManager.getUserLoginData(LoginModel.class).getResult().getCenterId(),
sharePreferenceManager.getUserLoginData(LoginModel.class).getResult().getTabID(),
ComponentUtils.getInputStringFromView(searchText));
}
}
saerchButton.setOnClickListener(this);
}
/**
* Searching For Patient List
* #param centerId
* #param tabID
* #param searchtext
*/
private void getPayientSearchListOnline(String centerId, String tabID,String searchtext){
progressBar.setVisibility(View.VISIBLE);
Call<Result> profileModelCall = webService.getPatientSearchList(getMap(centerId,tabID,searchtext));
profileModelCall.enqueue(new Callback<Result>() {
#Override
public void onResponse(Call<Result> call, Response<Result> response) {
if (response.isSuccessful()) {
//if (response.body().isStatus()) {
recyclerView.setVisibility(View.GONE);
Result jsonResponse = response.body();
searchList = new ArrayList<>(Arrays.asList(jsonResponse.getResult()));
mSearchAdapter = new PatientSearchAdapter(searchList);
recyclerViewOnSearch.setAdapter(mSearchAdapter);
} else {
APIError apiError = ErrorUtils.parseError(response);
Toast.makeText(context, ""+ apiError.message(), Toast.LENGTH_SHORT).show();
}
if (progressBar.isEnabled())
progressBar.setVisibility(View.INVISIBLE);
progressBar.setVisibility(View.GONE);
}
#Override
public void onFailure(Call<Result> call, Throwable t) {
Toasty.error(getActivity(), "Please Try Again", Toast.LENGTH_SHORT, true).show();
if (progressBar.isEnabled())
progressBar.setVisibility(View.INVISIBLE);
progressBar.setVisibility(View.GONE);
}
});
}
/* *
* preparing Map data with param data
*/
private Map<String, RequestBody> getMap(String centerId, String tabId, String searchText) {
//All the String parameters, you have to put like
Map<String, RequestBody> map = new HashMap<>();
if (sharePreferenceManager != null && sharePreferenceManager.isUserLogin())
map.put("center_id", toRequestBody(centerId));
map.put("tabID", toRequestBody(tabId));
map.put("patient_search", toRequestBody(searchText));
return map;
}
/**
* This method converts String to RequestBody
*/
public static RequestBody toRequestBody(String value) {
return RequestBody.create(MediaType.parse("multipart/form-data"), value);
}
Api Call Interface
#Multipart
#POST(WebServices.GET_SEARCH_LIST)
Call<Result> getPatientSearchList(#PartMap Map<String, RequestBody> params);
what i am trying to do here is i am taking 1 edit text where i am putting number to enter , sending centerid,and tabID as parameter and for that i am doing Api Calling using Retrofit. but my problem is that whenever it goes to public void onResponse(Call call, Response response) {
it comes out from there and goes to failure and i am not getting the result after clicking the button.its showing me nothing .
TestListModel.class
public class TestListModel {
private String testlist_id;
private String test_price;
private String test_name;
private boolean isSelected;
public TestListModel(String testlist_id, String test_price, String test_name,boolean isSelected) {
this.testlist_id = testlist_id;
this.test_price = test_price;
this.test_name = test_name;
this.isSelected = isSelected;
}
public String getTestlist_id() {
return testlist_id;
}
public void setTestlist_id(String testlist_id) {
this.testlist_id = testlist_id;
}
public String getTest_price() {
return test_price;
}
public void setTest_price(String test_price) {
this.test_price = test_price;
}
public String getTest_name() {
return test_name;
}
public void setTest_name(String test_name) {
this.test_name = test_name;
}
public boolean isSelected() {
return isSelected;
}
public void setSelected(boolean isSelected) {
this.isSelected = isSelected;
}
}
JsonResponse.java
public class JSONResponse {
private TestListModel[] result;
public TestListModel[] getResult() {
return result;
}
public void setResult(TestListModel[] result) {
this.result = result;
}
}
HealthActivity.java
public class HealthServicesActivity extends AppCompatActivity implements View.OnClickListener {
/*
*Api call
* */
private RecyclerView recyclerView;
private ArrayList<TestListModel> data;
private RecyclerAdapter madapter;
private Button submitButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_health_services);
ButterKnife.bind(this);
sharePreferenceManager = new SharePreferenceManager<>(getApplicationContext());
submitButton=(Button) findViewById(R.id.submit_button);
showcenterid(sharePreferenceManager.getUserLoginData(LoginModel.class));
initViews();
submitButton.setOnClickListener(this);
/*
* On Click Listner
* */
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.submit_button:
int totalAmount = 0;
int totalPrice = 0;
String testName = "";
String testPrice="";
int count = 0;
List<TestListModel> stList = ((RecyclerAdapter) madapter)
.getTestList();
for (int i = 0; i < stList.size(); i++) {
TestListModel singleStudent = stList.get(i);
//AmountCartModel serialNumber = stList.get(i);
if (singleStudent.isSelected() == true) {
testName = testName + "\n" + singleStudent.getTest_name().toString();
testPrice = testPrice+"\n" + singleStudent.getTest_price().toString();
count++;
totalAmount = Integer.parseInt(stList.get(i).getTest_price());
totalPrice = totalPrice + totalAmount;
}
}
Toast.makeText(HealthServicesActivity.this,
"Selected Lists: \n" + testName+ "" + testPrice, Toast.LENGTH_LONG)
.show();
Intent in= new Intent(HealthServicesActivity.this, AmountCartActivity.class);
in.putExtra("test_name", testName);
in.putExtra("test_price", testPrice);
//in.putExtra("total_price",totalPrice);
in.putExtra("total_price", totalPrice);
in.putExtra("serialNumber", count);
startActivity(in);
finish();
break;
/** back Button Click
* */
case R.id.back_to_add_patient:
startActivity(new Intent(getApplicationContext(), PatientActivity.class));
finish();
break;
default:
break;
}
}
/** show center Id in action bar
* */
#Override
protected void onResume() {
super.onResume();
showcenterid(sharePreferenceManager.getUserLoginData(LoginModel.class));
}
private void showcenterid(LoginModel userLoginData) {
centerId.setText(userLoginData.getResult().getGenCenterId());
centerId.setText(userLoginData.getResult().getGenCenterId().toUpperCase());
deviceModeName.setText(userLoginData.getResult().getDeviceModeName());
}
private void initViews() {
recyclerView = (RecyclerView)findViewById(R.id.test_list_recycler_view);
recyclerView.setHasFixedSize(true);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(layoutManager);
loadJSON();
}
private void loadJSON() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(" http://192.168.1.80/aoplnew/api/")
//
.baseUrl("https://earthquake.usgs.gov/fdsnws/event/1/query?")
.addConverterFactory(GsonConverterFactory.create())
.build();
ApiInterface request = retrofit.create(ApiInterface.class);
Call<JSONResponse> call = request.getTestLists();
call.enqueue(new Callback<JSONResponse>() {
#Override
public void onResponse(Call<JSONResponse> call, Response<JSONResponse> response) {
JSONResponse jsonResponse = response.body();
data = new ArrayList<>(Arrays.asList(jsonResponse.getResult()));
madapter = new RecyclerAdapter(data);
recyclerView.setAdapter(madapter);
}
#Override
public void onFailure(Call<JSONResponse> call, Throwable t) {
Log.d("Error",t.getMessage());
}
});
}
HealthRecyclerAdapter.java
public class RecyclerAdapter extends
RecyclerView.Adapter<RecyclerAdapter.ViewHolder> {
private ArrayList<TestListModel> android;
public RecyclerAdapter(ArrayList<TestListModel> android) {
this.android = android;
}
#Override
public RecyclerAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.test_list_row,parent,false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(RecyclerAdapter.ViewHolder holder, final int position) {
holder.test_name.setText(android.get(position).getTest_name());
holder.test_price.setText(android.get(position).getTest_price());
holder.chkSelected.setChecked(android.get(position).isSelected());
holder.chkSelected.setTag(android.get(position));
holder.chkSelected.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
CheckBox cb = (CheckBox) v;
TestListModel contact = (TestListModel) cb.getTag();
contact.setSelected(cb.isChecked());
android.get(position).setSelected(cb.isChecked());
Toast.makeText(
v.getContext(),
"Clicked on Checkbox: " + cb.getText() + " is " + cb.isChecked(), Toast.LENGTH_LONG).show();
}
});
}
#Override
public int getItemCount() {
return android.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
private TextView test_name;
private TextView test_price;
public CheckBox chkSelected;
public TestListModel testLists;
public ViewHolder(View itemView) {
super(itemView);
test_name = (TextView)itemView.findViewById(R.id.test_name);
test_price = (TextView)itemView.findViewById(R.id.price_name);
chkSelected = (CheckBox) itemView.findViewById(R.id.check_box);
}
}
// method to access in activity after updating selection
public List<TestListModel> getTestList() {
return android;
}
AmountCartModel.java
public class AmountCartModel {
private String testName;
private String testPrice;
private Integer serialNumber;
private Integer totalPrice;
public AmountCartModel() {
this.testName = testName;
this.testPrice = testPrice;
this.serialNumber = serialNumber;
this.totalPrice = totalPrice;
}
public String getTestName() {
return testName;
}
public void setTestName(String testName) {
this.testName = testName;
}
public String getTestPrice() {
return testPrice;
}
public void setTestPrice(String testPrice) {
this.testPrice = testPrice;
}
public Integer getSerialNumber() {
return serialNumber;
}
public void setSerialNumber(Integer serialNumber) {
this.serialNumber = serialNumber;
}
public Integer getTotalPrice() {
return totalPrice;
}
public void setTotalPrice(Integer totalPrice) {
this.totalPrice = totalPrice;
}
}
AmountCartActivity.java
public class AmountCartActivity extends AppCompatActivity implements View.OnClickListener {
#BindView(R.id.total_price)
TextView totalPriceDisplay;
SharePreferenceManager<LoginModel> sharePreferenceManager;
private RecyclerView recyclerView;
List<AmountCartModel> mydataList ;
private MyAdapter madapter;
Bundle extras ;
String testName="";
String testPrice="";
String totalPrice= "";
int counting = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_amount_cart);
ButterKnife.bind(this);
sharePreferenceManager = new SharePreferenceManager<>(getApplicationContext());
showcenterid(sharePreferenceManager.getUserLoginData(LoginModel.class));
mydataList = new ArrayList<>();
/*
* Getting Values From BUNDLE
* */
extras = getIntent().getExtras();
if (extras != null) {
testName = extras.getString("test_name");
testPrice = extras.getString("test_price");
totalPrice = String.valueOf(extras.getInt("total_price"));
counting = extras.getInt("serialNumber");
//Just add your data in list
AmountCartModel mydata = new AmountCartModel(); // object of Model Class
mydata.setTestName(testName );
mydata.setTestPrice(testPrice);
mydata.setTotalPrice(Integer.valueOf(totalPrice));
mydata.setSerialNumber(counting);
mydataList.add(mydata);
//totalPriceDisplay.setText(totalPrice);
}
madapter=new MyAdapter(mydataList);
madapter.setMyDataList(mydataList);
recyclerView = (RecyclerView)findViewById(R.id.recyler_amount_cart);
recyclerView.setHasFixedSize(true);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(madapter);
RecyclerAdapter.java //RecyclerAdapter for AmountCart
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder>
{
private List<AmountCartModel> context;
private List<AmountCartModel> myDataList;
public MyAdapter(List<AmountCartModel> context) {
this.context = context;
myDataList = new ArrayList<>();
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
// Replace with your layout
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.amount_cart_row, parent, false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(ViewHolder holder, int position) {
// Set Your Data here to yout Layout Components..
// to get Amount
/* myDataList.get(position).getTestName();
myDataList.get(position).getTestPrice();*/
holder.testName.setText(myDataList.get(position).getTestName());
holder.testPrice.setText(myDataList.get(position).getTestPrice());
holder.textView2.setText(myDataList.get(position).getSerialNumber());
}
#Override
public int getItemCount() {
/*if (myDataList.size() != 0) {
// return Size of List if not empty!
return myDataList.size();
}
return 0;*/
return myDataList.size();
}
public void setMyDataList(List<AmountCartModel> myDataList) {
// getting list from Fragment.
this.myDataList = myDataList;
notifyDataSetChanged();
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView testName,testPrice,textView2;
public ViewHolder(View itemView) {
super(itemView);
// itemView.findViewById
testName=itemView.findViewById(R.id.test_name_one);
testPrice=itemView.findViewById(R.id.test_price);
textView2=itemView.findViewById(R.id.textView2);
}
}
}
#Override
public void onBackPressed() {
super.onBackPressed();
startActivity(new
Intent(AmountCartActivity.this,HealthServicesActivity.class));
finish();
}
}
This is my code.
Here I am taking HealthActivity and in this class by using recycler view I have displayed testList in recycler view. I am passing testList whichever I am selecting through checkbox to AmountCartActivity of recycler View, And, I am calculating total amount of the selected testList and I am getting the result and that result I am passing to the AmountCart Activity through bundle and I am getting correct result in bundle, but, when I am trying to display total amount in a textView its showing me nothing.
And, my second problem is,
I am trying to display serial number to to my AmountCartActivity of recycler view whichever I am selecting from previous HealthCartActivity using checkbox. And, I have implemented some code but I am not getting how to solve it. please help me.
For Issue#1
Data should be passed onto the Adapter through constructor. The issue could simply be adding another parameter to the constructor:
public MyAdapter(List<AmountCartModel> context, List<AmountCartModel> myDataList) {
this.context = context;
myDataList = this.myDataList;
}
Or,
To add selection support to a RecyclerView instance:
Determine which selection key type to use, then build a ItemKeyProvider.
Implement ItemDetailsLookup: it enables the selection library to access information about RecyclerView items given a MotionEvent.
Update item Views in RecyclerView to reflect that the user has selected or unselected it.
The selection library does not provide a default visual decoration for the selected items. You must provide this when you implement onBindViewHolder() like,
In onBindViewHolder(), call setActivated() (not setSelected()) on the View object with true or false (depending on if the item is selected).
Update the styling of the view to represent the activated status.
For Issue #2
Try using passing data through intents.
The easiest way to do this would be to pass the serial num to the activity in the Intent you're using to start the activity:
Intent intent = new Intent(getBaseContext(), HealthServicesActivity.class);
intent.putExtra("EXTRA_SERIAL_NUM", serialNum);
startActivity(intent);
Access that intent on next activity
String sessionId= getIntent().getStringExtra("EXTRA_SERIAL_NUM");
Hey guys iam trying to build a Social Media Application useing Firebase Realtime Database
but am Stuck in how to get the posts generated key to add the Comments inside it so how to get the push key generated to the post and how to show the comment inside the Clicked Post
Database Structure
Here is the Activity that Shows the Post Details When i click on the post in Recyclerview it Intents me to this Activity
public class ShowThePost extends AppCompatActivity {
Dialog dialog;
FirebaseUser mAuth;
DatabaseReference dbRef;
Intent intent;
#BindView(R.id.imgPostShow) PhotoView PostImage;
#BindView(R.id.Show_profile_image) CircularImageView UserProfilePicture;
#BindView(R.id.postTitleShow) TextView PostTitle;
#BindView(R.id.txt_Show_UserName) TextView UserProfileName;
#BindView(R.id.txt_Post_Date) TextView PostDateTime;
#BindView(R.id.Show_price) TextView RealPrice;
#BindView(R.id.txtShowDescription) TextView PostDescription;
#BindView(R.id.fabComment) com.getbase.floatingactionbutton.FloatingActionButton floatingActionsMenu;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_the_post);
ButterKnife.bind(this);
dialog = new Dialog(this);
intent = getIntent();
getDataFromIntent();
}
public void getDataFromIntent(){
String id = intent.getStringExtra("post_ID");
String title = intent.getStringExtra("post_Title");
String description = intent.getStringExtra("post_Desc");
String image = intent.getStringExtra("post_Image");
String dateTime = intent.getStringExtra("post_DateTime");
String price = intent.getStringExtra("post_Price");
String currency = intent.getStringExtra("post_Currency");
String UserName = intent.getStringExtra("post_UserName");
String UserProfilePic = intent.getStringExtra("post_UserProfilePicture");
GlideApp.with(this)
.load(image)
.into(PostImage);
GlideApp.with(this)
.load(UserProfilePic)
.into(UserProfilePicture);
PostTitle.setText(title);
UserProfileName.setText(UserName);
PostDescription.setText(description);
RealPrice.setText(price + " : " + currency);
PostDateTime.setText(dateTime);
}
public void ShowCommentDialog() {
// final AlertDialog.Builder alert = new AlertDialog.Builder(this);
// View view = getLayoutInflater().inflate(R.layout.create_comment,null);
// alert.setCancelable(false);
dialog.setContentView(R.layout.create_comment);
final EditText txtSuggestprice = (EditText) dialog.findViewById(R.id.priceSuggested);
final EditText txtNotes = (EditText)dialog.findViewById(R.id.txtnotes);
final Button btnDone = (Button)dialog.findViewById(R.id.btnCommentDone);
final Button btnClose = (Button) dialog.findViewById(R.id.btnClose);
btnDone.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final String category = intent.getStringExtra("category");
// String Notes = txtNotes.getText().toString();
// String SuggestedPrice =
//
txtSuggestprice.getText().toString();
// String UserID = mAuth.getUid().toString();
// String UserProfilePic = mAuth.getPhotoUrl().toString();
// String UserName = mAuth.getDisplayName().toString();
//
// CommentsList commentsList = new CommentsList();
// commentsList.setUserID(UserID);
// commentsList.setUserProfilePicture(UserProfilePic);
// commentsList.setCommentDescription(Notes);
// commentsList.setCommentSuggestPrice(SuggestedPrice);
// commentsList.setCommentDate("date");
//
dbRef = FirebaseDatabase.getInstance().getReference("Posts");
Toast.makeText(ShowThePost.this, dbRef.child(category).push().getKey().toString(), Toast.LENGTH_SHORT).show();
}
});
btnClose.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
Toasty.info(ShowThePost.this, "Canceled", Toast.LENGTH_SHORT).show();
}
});
dialog.setCancelable(false);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
}
#OnClick(R.id.fabComment)
public void OpenDialog(){
ShowCommentDialog();
}
}
and this is the Adapter used to send the data to the Recyclerview and Get the putExtra
public class BooksAdapter extends RecyclerView.Adapter<BooksAdapter.BooksItemsHolder> {
public BooksAdapter(List<BooksLists> listy, Context mContext) {
this.listy = listy;
this.mContext = mContext;
}
public List<BooksLists> listy ;
Context mContext;
#NonNull
#Override
public BooksItemsHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_item,parent,false);
BooksItemsHolder holder = new BooksItemsHolder(v);
return holder;
}
#Override
public void onBindViewHolder(#NonNull final BooksItemsHolder holder, int position) {
final BooksLists list = listy.get(position);
holder.PostTitle.setText(list.getPost_title());
holder.PostDate.setText(list.getPost_datetime());
GlideApp.with(mContext)
.load(list.getPost_image())
.into(holder.imgPostCover);
holder.UserProfileName.setText(list.getUser_name());
GlideApp.with(mContext)
.load(list.getUser_pp())
.placeholder(R.drawable.user)
.into(holder.TheUserProfilePic);
holder.linearLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(mContext,ShowThePost.class);
intent.putExtra("post_ID",list.getPost_id());
intent.putExtra("post_Title",list.getPost_title());
intent.putExtra("post_Desc",list.getPost_description());
intent.putExtra("post_Image",list.getPost_image());
intent.putExtra("post_DateTime",list.getPost_datetime());
intent.putExtra("post_Price",list.getPost_real_price());
intent.putExtra("post_Currency",list.getCurrency());
intent.putExtra("post_UserName",list.getUser_name());
intent.putExtra("post_UserProfilePicture",list.getUser_pp());
intent.putExtra("category",list.getCategory());
mContext.startActivity(intent);
}
});
}
#Override
public int getItemCount() {
return listy.size();
}
public class BooksItemsHolder extends RecyclerView.ViewHolder {
#BindView(R.id.TheuserProfilePicture)
CircularImageView TheUserProfilePic;
#BindView(R.id.userName) TextView UserProfileName;
#BindView(R.id.imgPostShow) ImageView imgPostCover;
#BindView(R.id.postTitle) TextView PostTitle;
#BindView(R.id.txt_Post_Date) TextView PostDate;
#BindView(R.id.GotoPostItem)
CardView linearLayout;
public BooksItemsHolder(View itemView) {
super(itemView);
ButterKnife.bind(this,itemView);
}
}
}
List of the Comments.class
public class CommentsList {
public CommentsList() {
}
String userID;
String userName;
String userProfilePicture;
String commentDate;
String commentSuggestPrice;
String CommentDescription;
public String getUserID() {
return userID;
}
public void setUserID(String userID) {
this.userID = userID;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserProfilePicture() {
return userProfilePicture;
}
public void setUserProfilePicture(String userProfilePicture) {
this.userProfilePicture = userProfilePicture;
}
public String getCommentDate() {
return commentDate;
}
public void setCommentDate(String commentDate) {
this.commentDate = commentDate;
}
public String getCommentSuggestPrice() {
return commentSuggestPrice;
}
public void setCommentSuggestPrice(String commentSuggestPrice) {
this.commentSuggestPrice = commentSuggestPrice;
}
public String getCommentDescription() {
return CommentDescription;
}
public void setCommentDescription(String commentDescription) {
CommentDescription = commentDescription;
}
public CommentsList(String userID, String userName, String userProfilePicture, String commentDate, String commentSuggestPrice, String commentDescription) {
this.userID = userID;
this.userName = userName;
this.userProfilePicture = userProfilePicture;
this.commentDate = commentDate;
this.commentSuggestPrice = commentSuggestPrice;
CommentDescription = commentDescription;
}
}
You can try this
mDatabase.child("Posts").child("Books").addValueEventListener(new ValueEventListener() {
final ArrayList<String> keysArray= new ArrayList<String>(); // if you want to store all the keys
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot data : dataSnapshot.getChildren()){
String key = data.getKey(); //Here you can get all your keys from Books
keysArray.add(key);
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(view.getContext(),"database error",
Toast.LENGTH_SHORT).show();
}
});
I have recyclerview recieving data from firebase and i want to make last item uploaded to be first item in the list.I'm using GridLayoutManager and want to display a pic with a text, all of this work fine but i want to make them in order like instagram, does any one know something like that ?
Here is my code
public class ItemsUser extends Fragment {
private View mMainView;
private RecyclerView mUsersList;
private String user_id;
private DatabaseReference mUserDatabase;
private FirebaseRecyclerAdapter<ItemRecycleview,UserRecycleView> firebaseRecyclerAdapter;
private DatabaseReference mDatabaseReference;
private FirebaseListAdapter<ItemRecycleview> firebaseListAdapter;
public ItemsUser() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
mMainView = inflater.inflate(R.layout.fragment_items_user, container, false);
mUsersList = (RecyclerView) mMainView.findViewById(R.id.recyclerView_profile);
mUsersList.setHasFixedSize(true);
mUsersList.setLayoutManager(new GridLayoutManager(getActivity(),3));
ProfileUser activity = (ProfileUser) getActivity();
user_id = activity.getMyData();
mDatabaseReference = FirebaseDatabase.getInstance().getReference();
mUserDatabase = FirebaseDatabase.getInstance().getReference().child("Users_photos").child(user_id);
mUserDatabase.keepSynced(true);
return mMainView;
}
#Override
public void onStart() {
super.onStart();
firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<ItemRecycleview, UserRecycleView>(
ItemRecycleview.class,
R.layout.recycleview_item,
UserRecycleView.class,
mUserDatabase
) {
#Override
protected void populateViewHolder(UserRecycleView viewHolder, ItemRecycleview model, int position) {
viewHolder.setImageName(model.getImageName());
viewHolder.setImageURL(model.getImageURL(),getContext());
viewHolder.mView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String key = firebaseRecyclerAdapter.getRef(mUsersList.getChildLayoutPosition(v)).getKey();
Intent imageIntent = new Intent(getActivity(), ImageActivity.class);
imageIntent.putExtra("imageKey",key);
imageIntent.putExtra("user_id",user_id);
startActivity(imageIntent);
}
});
}
};
mUsersList.setAdapter(firebaseRecyclerAdapter);
}
public static class UserRecycleView extends RecyclerView.ViewHolder {
View mView;
public UserRecycleView(View itemView) {
super(itemView);
mView = itemView;
}
public void setImageName(String imageName){
TextView userNameView = (TextView) mView.findViewById(R.id.ImageNameTextView);
userNameView.setText(imageName);
}
public void setImageURL(final String imageURL,final Context ctx){
final ImageView userImageView = (ImageView) mView.findViewById(R.id.imageView);
Picasso.with(ctx).load(imageURL).networkPolicy(NetworkPolicy.OFFLINE).into(userImageView, new Callback() {
#Override
public void onSuccess() {
}
#Override
public void onError() {
Picasso.with(ctx).load(imageURL).into(userImageView);
}
});
}
}
}
and this is ItemRecyclerview:
public class ItemRecycleview {
public String imageName;
public String imageURL;
public ItemRecycleview(){
}
public ItemRecycleview(String imageName, String imageURL) {
this.imageName = imageName;
this.imageURL = imageURL;
}
public String getImageName() {
return imageName;
}
public void setImageName(String imageName) {
this.imageName = imageName;
}
public String getImageURL() {
return imageURL;
}
public void setImageURL(String imageURL) {
this.imageURL = imageURL;
}
}
hey guys i just found the answer :D
all you need to do is to add this method in firebaseRecyclerAdapter
here it's:
firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<ItemRecycleview, UserRecycleView>(
ItemRecycleview.class,
R.layout.recycleview_item,
UserRecycleView.class,
mUserDatabase
) {
#Override
public ItemRecycleview getItem(int position) {
return super.getItem(getItemCount() - 1 - position);
}
#Override
protected void populateViewHolder(UserRecycleView viewHolder, ItemRecycleview model, int position) {
viewHolder.setImageName(model.getImageName());
viewHolder.setImageURL(model.getImageURL(),getContext());
viewHolder.mView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String key = firebaseRecyclerAdapter.getRef(mUsersList.getChildLayoutPosition(v)).getKey();
Intent imageIntent = new Intent(getActivity(), ImageActivity.class);
imageIntent.putExtra("imageKey",key);
imageIntent.putExtra("user_id",user_id);
startActivity(imageIntent);
}
});
}
};
and that will make it done
Have you tried using setReverseLayout() method to make first element last in the list
GridLayoutManager mLayoutManager = new GridLayoutManager(getActivity(),3);
mLayoutManager.setReverseLayout(true);
mLayoutManager.setStackFromEnd(true);
mUsersList.setLayoutManager(mLayoutManager);
what can be the reason that firebase gives databaseException error? I am new to android firebase adapter and I am facing an issue of databaseException. I was trying to get adapter in MainCommentFragment so I can use viewPager and recyclerview. But it seems like there is an error when I call mRecyclerView.setAdapter(mCommentAdapter); in MainCommentFragment.java. Can anyone help me with this?
Comment.java
public class Comment
{
public String uid;
public String username;
public String body;
public String time;
public String choice;
public int likeCount;
public int dislikeCount;
public Map<String, Boolean> likes = new HashMap<>();
public Map<String, Boolean> dislikes = new HashMap<>();
public Comment()
{
}
public Comment(String uid, String username, String body, String time, String choice)
{
this.uid = uid;
this.username = username;
this.body = body;
this.time = time;
this.choice = choice;
}
public Map<String, Object> toMap()
{
HashMap<String, Object> result = new HashMap<>();
result.put("uid", uid);
result.put("username", username);
result.put("time", time);
result.put("body", body);
result.put("likeCount", likeCount);
result.put("dislikeCount", dislikeCount);
result.put("likes", likes);
result.put("dislikes", dislikes);
result.put("choice", choice);
return result;
}
}
MainCommentFragment.java
public abstract class MainCommentFragment extends Fragment
{
/*UI*/
private RecyclerView mRecyclerView; //declaring recycler view
/*Firebase*/
private DatabaseReference mDatabase; //declaring database
/*Other*/
private FirebaseRecyclerAdapter<Comment, CommentViewHolder> mCommentAdapter; //declaring adapter for post
private LinearLayoutManager mLinearLayoutManager; //declaring linear layout manager
private String postKey;
/*Function*/
public MainCommentFragment() //creating a constructor for MainFragment
{
}
#Override
public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) //when view is created
{
super.onCreateView(inflater, container, savedInstanceState);
View rootView = inflater.inflate(R.layout.fragment_comment, container, false); //fragment_all_posts will invoked
mDatabase = FirebaseDatabase.getInstance().getReference(); //initializing database
mRecyclerView = (RecyclerView)rootView.findViewById(R.id.fragment_comment_recycler_view); //initializing recycler view
mRecyclerView.setHasFixedSize(true); //giving fixed size property to recycler view
RoomActivity roomActivity = (RoomActivity)getActivity();
postKey = roomActivity.getPostKey();
System.out.println("postKey=============================" + postKey);
return rootView; //returning view
}
#Override
public void onActivityCreated(Bundle savedInstanceState) //when activity is created
{
super.onActivityCreated(savedInstanceState);
mLinearLayoutManager = new LinearLayoutManager(getActivity()); //initializing linear layout manager
mLinearLayoutManager.setReverseLayout(true); //make the layout reverse
mLinearLayoutManager.setStackFromEnd(true); //make the layout stack from end
mRecyclerView.setLayoutManager(mLinearLayoutManager); //initialize recycler view
Query commentQuery = getQuery(mDatabase, postKey); //get query for database
mCommentAdapter = new FirebaseRecyclerAdapter<Comment, CommentViewHolder>(Comment.class, R.layout.comment_item, CommentViewHolder.class, commentQuery) //initializing post adapter
{
#Override
protected void populateViewHolder(CommentViewHolder viewHolder, Comment model, int position)
{
viewHolder.bindToComment(model, new View.OnClickListener()
{
#Override
public void onClick(View v)
{
DatabaseReference globalCommentRef = mDatabase.child("Comment").child(postKey);
onLikeClicked(globalCommentRef);
switch(v.getId())
{
case R.id.comment_item_like_btn:
onLikeClicked(globalCommentRef);
break;
case R.id.comment_item_dislike_btn:
onDislikeClicked(globalCommentRef);
break;
}
}
});
}
};
mRecyclerView.setAdapter(mCommentAdapter); //recycler view will not display post adapter
}
private void onLikeClicked(DatabaseReference commentRef)
{
commentRef.runTransaction(new Transaction.Handler()
{
#Override
public Transaction.Result doTransaction(MutableData mutableData)
{
Comment c = mutableData.getValue(Comment.class);
if(c == null)
{
return Transaction.success(mutableData);
}
if(c.likes.containsKey(FirebaseAuth.getInstance().getCurrentUser().getUid()))
{
} else
{
c.likeCount = c.likeCount + 1;
c.likes.put(FirebaseAuth.getInstance().getCurrentUser().getUid(), true);
if(c.dislikeCount != 0)
{
c.dislikeCount = c.dislikeCount - 1;
c.dislikes.remove(FirebaseAuth.getInstance().getCurrentUser().getUid());
}
}
mutableData.setValue(c);
return Transaction.success(mutableData);
}
#Override
public void onComplete(DatabaseError databaseError, boolean b, DataSnapshot dataSnapshot)
{
}
});
}
private void onDislikeClicked(DatabaseReference commentRef)
{
commentRef.runTransaction(new Transaction.Handler()
{
#Override
public Transaction.Result doTransaction(MutableData mutableData)
{
Comment c = mutableData.getValue(Comment.class);
if(c == null)
{
return Transaction.success(mutableData);
}
if(c.dislikes.containsKey(FirebaseAuth.getInstance().getCurrentUser().getUid()))
{
} else
{
c.dislikeCount = c.dislikeCount + 1;
c.dislikes.put(FirebaseAuth.getInstance().getCurrentUser().getUid(), true);
if(c.likeCount != 0)
{
c.likeCount = c.likeCount - 1;
c.likes.remove(FirebaseAuth.getInstance().getCurrentUser().getUid());
}
}
mutableData.setValue(c);
return Transaction.success(mutableData);
}
#Override
public void onComplete(DatabaseError databaseError, boolean b, DataSnapshot dataSnapshot)
{
}
});
}
public abstract Query getQuery(DatabaseReference databaseReference, String postKey); //declaring query
}
This is the error message.
com.google.firebase.database.DatabaseException: Can't convert object of type java.lang.Long to type packagename.Comment