RecyclerView onCreateViewHolder does not run - android

I have search for hours and i'm sure its something simple but i can't find the answer. onCreateViewHolder and onBindViewHolder does not run. can someone help me out. thanks
MainActivity.java
public class MainActivity extends AppCompatActivity {
private RecyclerView mBlogList;
private DatabaseReference mDatabase;
private Query query = FirebaseDatabase.getInstance().getReference().child("Blog").limitToLast(50);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDatabase = FirebaseDatabase.getInstance().getReference().child("Blog");
// query = FirebaseDatabase.getInstance().getReference().child("Blog").limitToLast(50);
mBlogList = findViewById(R.id.blog_list);
mBlogList.setHasFixedSize(true);
mBlogList.setLayoutManager(new LinearLayoutManager(this)); //sets the orientation to vertical
}
#Override
protected void onStart() {
super.onStart();
Toast.makeText(this, "1", Toast.LENGTH_SHORT).show();
FirebaseRecyclerOptions<Blog> options = new FirebaseRecyclerOptions.Builder<Blog>()
.setQuery(query, Blog.class)
.build();
Toast.makeText(this, "2", Toast.LENGTH_SHORT).show();
FirebaseRecyclerAdapter firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Blog, BlogViewHolder>(options) {
#Override
public BlogViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.blog_row, parent, false);
Toast.makeText(MainActivity.this, "oh oh", Toast.LENGTH_SHORT).show();
return new BlogViewHolder(view);
}
#Override
protected void onBindViewHolder(BlogViewHolder holder, int position, Blog model) {
holder.setTitle(model.getTitle());
holder.setDesc(model.getDesc());
Toast.makeText(MainActivity.this, "oh si", Toast.LENGTH_SHORT).show();
}
};
mBlogList.setAdapter(firebaseRecyclerAdapter);
}
public static class BlogViewHolder extends RecyclerView.ViewHolder {
View mView;
public BlogViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
public void setTitle(String title) {
TextView post_title = mView.findViewById(R.id.post_title);
post_title.setText(title);
}
public void setDesc(String desc) {
TextView post_desc = mView.findViewById(R.id.post_desc);
post_desc.setText(desc);
}
}
#Override
public boolean onCreateOptionsMenu (Menu menu){
getMenuInflater().inflate(R.menu.main_menu, menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected (MenuItem item){
if (item.getItemId() == R.id.action_add) {
startActivity(new Intent(getApplicationContext(), Postctivity.class));
}
return super.onOptionsItemSelected(item);
}
}
Blog.class
public class Blog {
private String title;
private String desc;
private String image;
public Blog(){
}
public Blog(String title, String desc, String image) {
this.title = title;
this.desc = desc;
this.image = image;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
}
blog_row.xml
public class Blog {
private String title;
private String desc;
private String image;
public Blog(){
}
public Blog(String title, String desc, String image) {
this.title = title;
this.desc = desc;
this.image = image;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
}

According to the documentation for the library you're using, you have to call adapter.startListening() to actually read information from your database.
The FirebaseRecyclerAdapter uses an event listener to monitor changes to the Firebase query. To begin listening for data, call the startListening() method. You may want to call this in your onStart() method. Make sure you have finished any authentication necessary to read the data before calling startListening() or your query will fail.
#Override
protected void onStart() {
super.onStart();
adapter.startListening();
}
It looks like you're doing all the setup of your adapter in onStart() already, so I think you can just add one line at the end:
firebaseRecyclerAdapter.startListening();

Noob trying to learn here. The recyclerView was not downloading the content from the firebase database. What I did to fix it was changing the from setHasFixedSize(true) to setHasFixedSize(false) Im not sure why it fixed it but it did. I know my question is confusing my english is not very good. I hope this help.

Related

SearchView on RecyclerView no work how to fix?

Hello I implemented a search but when trying to filter nothing happens someone knows some way to make it work correctly, I can't identify where it is wrong. Thanks in advance. any help is welcome.
Below are codes of my activity where is the recycler view. And model contacts.
I really don't know what I'm doing wrong.
Contacts Model
public class Contacts {
public String name, status, image;
public Contacts()
{
}
public Contacts(String name, String status, String image) {
this.name = name;
this.status = status;
this.image = image;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
}
My Activity
public class FindFriendsActivity extends AppCompatActivity
{
private Toolbar mToolbar;
private RecyclerView FindFriendsRecyclerList;
private DatabaseReference UsersRef;
private SearchView searchView;
private Query query;
private FirebaseRecyclerOptions<ColorSpace.Model> options;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_find_friends);
UsersRef = FirebaseDatabase.getInstance().getReference().child("Users");
FindFriendsRecyclerList = (RecyclerView) findViewById(R.id.find_friends_recycler_list);
FindFriendsRecyclerList.setLayoutManager(new LinearLayoutManager(this));
mToolbar = (Toolbar) findViewById(R.id.find_friends_toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setTitle("Find Friends");
searchView = findViewById(R.id.materialSearchPrincipal);
}
#Override
protected void onStart()
{
super.onStart();
FirebaseRecyclerOptions<Contacts> options =
new Builder<Contacts>()
.setQuery(UsersRef, Contacts.class)
.build();
FirebaseRecyclerAdapter<Contacts, FindFriendViewHolder> adapter =
new FirebaseRecyclerAdapter<Contacts, FindFriendViewHolder>(options) {
#Override
protected void onBindViewHolder(#NonNull FindFriendViewHolder holder, final int position, #NonNull Contacts model)
{
holder.userName.setText(model.getName());
holder.userStatus.setText(model.getStatus());
Picasso.get().load(model.getImage()).placeholder(R.drawable.profile_image).into(holder.profileImage);
holder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view)
{
String visit_user_id = getRef(position).getKey();
Intent profileIntent = new Intent(FindFriendsActivity.this, ProfileActivity.class);
profileIntent.putExtra("visit_user_id", visit_user_id);
startActivity(profileIntent);
}
});
}
#NonNull
#Override
public FindFriendViewHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int i)
{
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.users_display_layout, viewGroup, false);
FindFriendViewHolder viewHolder = new FindFriendViewHolder(view);
return viewHolder;
}
};
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
private void fetch(Query query) {
FirebaseRecyclerOptions<Contacts> options =
new Builder<Contacts>()
.setQuery(query, Contacts.class)
.build();
}
#Override
public boolean onQueryTextSubmit(String s) {
return false;
}
#Override
public boolean onQueryTextChange(String s) {
Query query = FirebaseDatabase.getInstance()
.getReference()
.child("User").orderByChild("name").equalTo(s);
if(s.equals("")){
query = FirebaseDatabase.getInstance()
.getReference()
.child("name");
}
fetch(query);
return false;
}
});
FindFriendsRecyclerList.setAdapter(adapter);
adapter.startListening();
}
public static class FindFriendViewHolder extends RecyclerView.ViewHolder
{
TextView userName, userStatus;
CircleImageView profileImage;
public FindFriendViewHolder(#NonNull View itemView)
{
super(itemView);
userName = itemView.findViewById(R.id.user_profile_name);
userStatus = itemView.findViewById(R.id.user_status);
profileImage = itemView.findViewById(R.id.users_profile_image);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.options_menu, menu);
MenuItem item = menu.findItem(R.id.menuPesquisa);
return true;
}
}
You need a new reference to adapter in fetch() method, because after every search the returned item count is changing. That's why in my example I have done like this in the fetch() method:
adapter = new CustomFirebaseRecylerAdapter<Model, CustomFirebaseRecylerAdapter.ViewHolder>(options);
adapter.startListening();
recyclerView.setAdapter(adapter);
try creating a new adapter instance in the fetch() method and then setting up the following:
adapter.startListening();
FindFriendsRecyclerList.setAdapter(adapter);

How do I make readable TimeStamp from Cloud Firestore?

So below are the database of my cloud firestore. That DatePosted shows 2nd December, 2019 at 8.19 pm UTC +8. According to the code I used and I run my app, it shows an unreadable number. Is it correct on how I retrieve the data from cloud firebase? If its wrong, how do I retrieve that timestamp and make it readable?
ForumAdapter.java
public class ForumAdapter extends FirestoreRecyclerAdapter<Forum,ForumAdapter.ForumHolder> {
private OnItemClickListener listener;
public ForumAdapter(FirestoreRecyclerOptions<Forum> options) {
super(options);
}
#Override
public void onBindViewHolder(ForumHolder forumHolder, int i, Forum forum) {
forumHolder.textViewTitle.setText(forum.getTitle());
forumHolder.textViewDescription.setText(forum.getDescription());
forumHolder.timeStamp.setText(forum.getDatePosted().toString());
}
#NonNull
#Override
public ForumHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
android.view.View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardviewforumtitle,parent,false);
return new ForumHolder(v);
}
class ForumHolder extends RecyclerView.ViewHolder{
TextView textViewTitle;
TextView textViewDescription;
TextView timeStamp;
public ForumHolder(View itemView) {
super(itemView);
textViewTitle = itemView.findViewById(R.id.tvTitle);
textViewDescription = itemView.findViewById(R.id.tvDescription);
timeStamp = itemView.findViewById(R.id.tvTimestamp);
textViewTitle.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int position = getAdapterPosition();
// NO_POSITION to prevent app crash when click -1 index
if(position != RecyclerView.NO_POSITION && listener !=null ){
listener.onItemClick(getSnapshots().getSnapshot(position),position);
}
}
});
}
}
public interface OnItemClickListener{
void onItemClick(DocumentSnapshot documentSnapshot, int position);
}
public void setOnItemClickListener(OnItemClickListener listener){
this.listener = listener;
}
#Override
public int getItemCount() {
return super.getItemCount();
}
}
Forum.java
public class Forum {
private String Title;
private String Description;
private String User;
private com.google.firebase.Timestamp DatePosted;
public Forum() {
}
public Forum(String title, String description, Timestamp datePosted,String user) {
Title = title;
Description = description;
DatePosted = datePosted;
User = user;
}
public String getUser() {
return User;
}
public void setUser(String user) {
User = user;
}
public String getTitle() {
return Title;
}
public void setTitle(String title) {
Title = title;
}
public String getDescription() {
return Description;
}
public void setDescription(String description) {
Description = description;
}
public Timestamp getDatePosted() {
return DatePosted;
}
public void setDatePosted(Timestamp datePosted) {
DatePosted = datePosted;
}
}
When you query a document with a timestamp field, you will get a Timestamp object back. If you'd rather have a Date object, you can use its toDate method.
You will need to write some code to format this for display. This is a very common task for mobile and web apps.

Firebase RecyclerView not displaying Anything

I have the same code for another database and it works just fine, I have no Idea why it's not working here,
the onCreateViewHolder does not even get called.
(Appearently Stacks Overflow wants me to add more details to compensate for too much code so here's some unuseful Text , Text, Text , TEXT).
public class Course extends AppCompatActivity {
private RecyclerView mLocationView;
private DatabaseReference mLocation;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_course);
mLocation = FirebaseDatabase.getInstance().getReference("FINISHEDCOURSES");
mLocation.keepSynced(true);
mLocationView = (RecyclerView) findViewById(R.id.my_recycler_view);
mLocationView.setHasFixedSize(true);
mLocationView.setLayoutManager(new LinearLayoutManager(this));
}
#Override
protected void onStart() {
super.onStart();
FirebaseRecyclerOptions<Courses> options = new FirebaseRecyclerOptions.Builder<Courses>().setQuery(mLocation, Courses.class).build();
FirebaseRecyclerAdapter<Courses, CourseViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Courses, CourseViewHolder>
(options) {
#Override
protected void onBindViewHolder(#NonNull CourseViewHolder holder, int position, #NonNull Courses model) {
holder.setText(model.getDate(), model.getDistance(), model.getDriver(), model.getPrice());
}
#NonNull
#Override
public CourseViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.courses_rows, parent, false);
return new CourseViewHolder(view);
}
};
mLocationView.setAdapter(firebaseRecyclerAdapter);
firebaseRecyclerAdapter.startListening();
}
public static class CourseViewHolder extends RecyclerView.ViewHolder{
View mView;
public CourseViewHolder(View itemView){
super(itemView);
mView = itemView;
}
public void setText(String Date, String start, String end, String price){
TextView dateText = mView.findViewById(R.id.dateText);
TextView startText = mView.findViewById(R.id.depart_text);
TextView endText = mView.findViewById(R.id.end_text);
TextView priceText = mView.findViewById(R.id.price);
dateText.setText(Date);
startText.setText(start);
endText.setText(end);
priceText.setText(price);
}
}
The Courses Class
public class Courses {
private String driver, date, distance, preWaitTime, price, waitTime, client;
public Courses() {
}
public Courses(String driver, String date, String distance, String preWaitTime, String price, String waitTime, String client) {
this.driver = driver;
this.date = date;
this.distance = distance;
this.preWaitTime = preWaitTime;
this.price = price;
this.waitTime = waitTime;
this.client = client;
}
public String getDriver() {
return driver;
}
public void setDriver(String driver) {
this.driver = driver;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getDistance() {
return distance;
}
public void setDistance(String distance) {
this.distance = distance;
}
public String getPreWaitTime() {
return preWaitTime;
}
public void setPreWaitTime(String preWaitTime) {
this.preWaitTime = preWaitTime;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getWaitTime() {
return waitTime;
}
public void setWaitTime(String waitTime) {
this.waitTime = waitTime;
}
public String getClient() {
return client;
}
public void setClient(String client) {
this.client = client;
}
}
Here's The Database Structure :
Sorry I should have commented but i do not have enough reputation to do so.
I cannot see anything similar to this in your code.
FirebaseRecyclerAdapter<Courses, CourseViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Courses, CourseViewHolder>(
Courses.class,
R.layout.Courses,// should be your layout name
CourseViewHolder.class,
mLocation
) {
#Override
protected void populateViewHolder(CourseViewHolder viewHolder, category model, final int position) {
viewHolder.setName(model.getName());
viewHolder.setImage(getApplicationContext(),model.getImage());

How to add search filter for RecyclerView while working with Firestore?

So, i'm trying to create app that shows list of writers(image,name,bio) and the thing is that I have problem implementing search functionality. The guide for working with RecyclerView I used is here.
Code: MainActivity
public class MainActivity extends AppCompatActivity {
private FirebaseFirestore db;
private FirestoreRecyclerAdapter adapter;
private LinearLayoutManager linearLayoutManager;//nodrosina kada veida recycle attelos
private List<Klasiki> list;
#BindView(R.id.imageRecycleView)
RecyclerView klasikiList; //tas pats kas find by ID
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
linearLayoutManager = new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.VERTICAL, false);
klasikiList.setLayoutManager(linearLayoutManager);
db = FirebaseFirestore.getInstance();
getList();
}
//atgriez ierakstus no datubazes un nodrosina atteloshanu recycle view
private void getList(){
Query query = db.collection("klasiki");
FirestoreRecyclerOptions<Klasiki> response = new FirestoreRecyclerOptions.Builder<Klasiki>()
.setQuery(query, Klasiki.class)
.build();
adapter = new FirestoreRecyclerAdapter<Klasiki, klasikiHolder>(response) {
#Override
protected void onBindViewHolder(final klasikiHolder holder, int position, final Klasiki model) {
holder.name.setText(model.getName());
holder.shortBio.setText(model.getShortBio());
Glide.with(getApplicationContext()).load(model.getImage()).into(holder.image);
holder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, BioActivity.class);
//Parnes mainigos uz bio activity
Bundle extras = new Bundle();
extras.putString("imageInfo", model.getImage());
extras.putString("nameInfo", model.getName());
extras.putString("bioInfo", model.getFullBio());
intent.putExtras(extras);
startActivity(intent);
}
});
}
#Override
public klasikiHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.klasiki_layout, parent, false);
return new klasikiHolder(view);
} //nodrosina jauna ieraksta returnu
#Override
public void onError(FirebaseFirestoreException e) {
Log.e("error", e.getMessage());
}
};
adapter.notifyDataSetChanged();
klasikiList.setAdapter(adapter);
}
//izsauc mainigos
public class klasikiHolder extends RecyclerView.ViewHolder{
#BindView(R.id.name)
TextView name;
#BindView(R.id.klasikiImage)
ImageView image;
#BindView(R.id.shortBio)
TextView shortBio;
public klasikiHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
}
#Override
protected void onStart() {
super.onStart();
adapter.startListening();
}
#Override
protected void onStop() {
super.onStop();
adapter.stopListening();
}
Constructor
public class Klasiki {
private String Name;
private String Image;
private String shortBio;
private String fullBio;
public Klasiki(){}
public Klasiki(String name, String image, String shortBio, String fullBio) {
Name = name;
Image = image;
this.shortBio = shortBio;
this.fullBio = fullBio;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getImage() {
return Image;
}
public void setImage(String image) {
Image = image;
}
public String getShortBio() {
return shortBio;
}
public void setShortBio(String shortBio) {
this.shortBio = shortBio;
}
public String getFullBio() {
return fullBio;
}
public void setFullBio(String fullBio) {
this.fullBio = fullBio;
}
}
I think I have to use other RecyclerViewthan FirestoreRecyclerOptions but i'm not sure, really new to android programming. :)
UPDATE:
So I made something like this:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.search_menu, menu);
// Retrieve the SearchView and plug it into SearchManager
final SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search));
SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
#Override
public boolean onQueryTextSubmit(String text) {
querySearch = db.collection("klasiki").whereEqualTo("name", text);
if (!text.trim().isEmpty()){
getList(querySearch);
adapter.startListening();
}
return false;
}
#Override
public boolean onQueryTextChange(String newText) {
if (newText.trim().isEmpty()){
getList(queryFinal);
adapter.startListening();
}
return false;
}
});
return true;
}
Probably not the best solution, but now I have different problem.. Is there a way to make sub string searches for Firestore? Like db.collection("klasiki").whereEqualTo("name", Ja); And it shows names where it starts with Ja.
In order to search for a writter you need to create a Query.
FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
Query nameOfTheWritterQuery = rootRef.collection("writters")
.whereEqualTo("writterName", "Eidemanis Roberts");
Seeing your Klasiki class, I need to tell you that you do not respect Java Naming Conventions rules for all your fields and you can have problems while deserializing. Your model class should look like this:
public class Klasiki {
private String name, image, shortBio, fullBio;
public Klasiki( ){}
public Klasiki(String name, String image, String shortBio, String fullBio) {
this.name = name;
this.image = image;
this.shortBio = shortBio;
this.fullBio = fullBio;
}
public String getName() {return name;}
public void setName(String name) {this.name = name;}
public String getImage() {return image;}
public void setImage(String image) {this.image = image;}
public String getShortBio() {return shortBio;}
public void setShortBio(String shortBio) {this.shortBio = shortBio;}
public String getFullBio() {return fullBio;}
public void setFullBio(String fullBio) {this.fullBio = fullBio;}
}
Please see the fields now. All start will small letter.

WebView implementation with Firebase Database in Android

I want to implement webView with Firebase so that if I add a URL in firebase Database it gets implemented on my webView in application in realtime, I have successfully implemented the text and images through database but could not get webView work correctly, I have searched many options but neither work for me, please help. If you want any more detail I can provide you.
I am using Android Studio
Below is my Java class code for Firebase implementation for Images and text
#Override
public void onStart() {
super.onStart();
FirebaseUser currentUser = mAuth.getCurrentUser();
if (currentUser == null) {
sentToStart();
}
FirebaseRecyclerAdapter <post, postViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<post, postViewHolder>(
post.class,
R.layout.post_row_recycle_home,
postViewHolder.class,
mDatabaseReference
) {
#Override
protected void populateViewHolder(postViewHolder viewHolder, post model, int position) {
viewHolder.setTitle(model.getTitle());
viewHolder.setdescription(model.getDescription());
viewHolder.setimage(getApplicationContext(), model.getImage());
viewHolder.setsource(model.getSource());
}
};
mrecyclerView.setAdapter(firebaseRecyclerAdapter);
}
public static class postViewHolder extends RecyclerViewPager.ViewHolder{
View mView;
public postViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
public void setTitle(String title){
TextView post_title = (TextView)mView.findViewById(R.id.title_cardView);
post_title.setText(title);
}
public void setsource(String source){
TextView post_source = (TextView)mView.findViewById(R.id.source_cardView);
post_source.setText(source);
}
public void setdescription(String description){
TextView post_description = (TextView)mView.findViewById(R.id.description_cardView);
post_description.setText(description);
}
public void setimage(final Context ctx, final String image){
final ImageView post_image = (ImageView)mView.findViewById(R.id.post_image);
Picasso.with(ctx).load(image).networkPolicy(NetworkPolicy.OFFLINE).into(post_image, new Callback() {
#Override
public void onSuccess() {
}
#Override
public void onError() {
Picasso.with(ctx).load(image).into(post_image);
}
});
}
}
Getter/Setter Java Class
public class post {
private String title;
private String description;
private String image;
private String source;
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public post(){
}
public post(String title, String description, String image, String source) {
this.title = title;
this.description = description;
this.image = image;
this.source = source;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
}
Updated: WebView java Activity
public class webViewNews extends AppCompatActivity {
private WebView webviewthis;
private DatabaseReference mDatabaseReference;
private DatabaseReference mdataRef;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview_page);
mdataRef = FirebaseDatabase.getInstance().getReference().child("webView");
webviewthis = (WebView)findViewById(R.id.webView_news);
webviewthis.setWebViewClient(new WebViewClient());
webviewthis.getSettings().setJavaScriptEnabled(true);
webviewthis.getSettings().setLoadsImagesAutomatically(true);
mdataRef.child("webView").addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
dataSnapshot.child("webView").getValue();
webviewthis.loadUrl("");
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
#Override
protected void onStart() {
super.onStart();
}
}
First of all, as i see in your code, you are using .child("webView") twice. Once in the DatabaseReference and once when you add the ValueEventListener. Is that what you are having in your database? If there are no duplicate childrens in your database, you need to remove one of them.
You have added a ValueEventListener on mdataRef but you are doing nothing there. Your onDataChange() method is empty. Remember, this method is triggered every time a change is taking place in your database. So in order to display some content, you need to get the data out from the dataSnapshot object according to your database structure and display it right there.
Hope it helps.

Categories

Resources