Failed to display data on RecyclerView - java

I'm following a tutorial on this Lapit Chat App - All Users Activity - Firebase Tutorials - Part 14. But i get my application to be corrupted when retrieving data from firebase. For previous tutorials all goes well without error. Just for this topic my app crashes. And all my code is the same as in the tutorial.
UserActivity.java
package com.bertho.chat;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class UsersActivity extends AppCompatActivity {
private Toolbar mToolbar;
private RecyclerView mUsersList;
private DatabaseReference mUsersDatabase;
private ProgressDialog mDialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_users);
mDialog = new ProgressDialog(this);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setTitle("User List");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mUsersDatabase = FirebaseDatabase.getInstance().getReference().child("Users");
mUsersList = (RecyclerView) findViewById(R.id.users_list);
mUsersList.setHasFixedSize(true);
mUsersList.setLayoutManager(new LinearLayoutManager(this));
}
#Override
protected void onStart() {
super.onStart();
showLoading("Get all user data");
FirebaseRecyclerAdapter<Users, UsersViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Users, UsersViewHolder>(
Users.class,
R.layout.users_single_layout,
UsersViewHolder.class,
mUsersDatabase
) {
#Override
protected void populateViewHolder(UsersViewHolder usersViewHolder, Users users, int position) {
usersViewHolder.setDisplayName(users.getName());
mDialog.dismiss();
}
};
mUsersList.setAdapter(firebaseRecyclerAdapter);
}
public static class UsersViewHolder extends RecyclerView.ViewHolder {
View mView;
public UsersViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
public void setDisplayName(String name) {
TextView userNameView = (TextView) mView.findViewById(R.id.user_single_name);
userNameView.setText(name);
}
}
private void showLoading(String s) {
mDialog.setTitle("Please waiting");
mDialog.setMessage(s);
mDialog.setCanceledOnTouchOutside(false);
mDialog.show();
}
}
activity_users.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.bertho.chat.UsersActivity">
<include layout="#layout/app_bar_layout"
android:id="#+id/user_appBar">
</include>
<android.support.v7.widget.RecyclerView
android:id="#+id/users_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/user_appBar">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
users_single_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#color/bgAbuAbu">
<android.support.v4.widget.CircleImageView
android:id="#+id/user_single_image"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_margin="10dp"
android:src="#drawable/notfound" />
<TextView
android:id="#+id/user_single_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/user_single_image"
android:layout_marginTop="14dp"
android:layout_toEndOf="#+id/user_single_image"
android:layout_toRightOf="#+id/user_single_image"
android:text="User default name!"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/user_single_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/user_single_name"
android:layout_marginTop="11dp"
android:layout_toEndOf="#+id/user_single_image"
android:layout_toRightOf="#+id/user_single_image"
android:text="User default status!" />
</RelativeLayout>
And my of Error Log on android studio
https://pastebin.com/UKhPswXQ
Is there anything wrong or missing on my code? Please help

your CircularImageView is not inflated and there was so many problems about it, solution use alternative library like hdodenhof CircularImageView link
add this to your dependencies :
compile 'de.hdodenhof:circleimageview:2.1.0'
and add the view like this :
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/profile_image"
android:layout_width="96dp"
android:layout_height="96dp"
android:src="#drawable/profile"
app:civ_border_width="2dp"
app:civ_border_color="#FF000000"/>

Related

Android Studio RecyclerView: Why always ( No adapter attached; skipping layout )

I am a student who currently taking mobile application development. Although my app can run but it doesnt show any activity instead of just give me W/RecyclerView: No adapter attached; skipping layout. I dont know how to solve the issue, so I was hoping can get some guidlines from experts.
Here is my code
MainActivity.java
package my.edu.utar.practicalassignment;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class MainActivity extends AppCompatActivity {
private Toolbar tool;
private TextView textView;
private RecyclerView recyclerView;
private Button AddBtn;
RecyclerView.LayoutManager layoutManager;
private FirebaseAuth auth;
private DatabaseReference ref;
private String userID = "";
private ProgressDialog progressDialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tool = findViewById(R.id.toolbar);
setSupportActionBar(tool);
//getSupportActionBar().setTitle("Today's Spending");
textView=findViewById(R.id.totalCashBack);
recyclerView =findViewById(R.id.recycle_view);
// recyclerView =(RecyclerView)findViewById(R.id.recycleView);
// layoutManager = new LinearLayoutManager(this);
// recyclerView.setLayoutManager(layoutManager);
AddBtn = findViewById(R.id.add_new);
auth = FirebaseAuth.getInstance();
userID = auth.getCurrentUser().getUid();
ref = FirebaseDatabase.getInstance().getReference().child("expenses").child(userID);
// if(userID !=null){
// try{
// ref = FirebaseDatabase.getInstance().getReference().child("expenses").child(userID);
//
// }catch (NullPointerException ex){
// ex.printStackTrace();
// }
// }
progressDialog = new ProgressDialog(this);
AddBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
addItem();
}
});
}
private void addItem() {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
LayoutInflater layout = LayoutInflater.from(this);
View view = layout.inflate(R.layout.input_layout, null);
alert.setView(view);
final AlertDialog dialog = alert.create();
dialog.setCancelable(false);
final Spinner spinnerItem = view.findViewById(R.id.spinner);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.category));
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerItem.setAdapter(adapter);
final EditText amount = view.findViewById(R.id.insert_amount);
final EditText notes = view.findViewById(R.id.insert_note);
final Button saveButton = view.findViewById(R.id.add_button);
final Button cancelButton = view.findViewById(R.id.cancel_button);
saveButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String amountGet = amount.getText().toString();
String notesGet = notes.getText().toString();
String categoryGet = spinnerItem.getSelectedItem().toString();
Drawable icon = getResources().getDrawable(R.drawable.error);
if(amountGet.isEmpty()){
amount.setError("Please enter an amount!!!", icon );
return;
}
if(notesGet.isEmpty()){
notes.setError("Please enter a notes!!!", icon );
return;
}
if(categoryGet.equals("Select a Category")){
Toast.makeText(MainActivity.this, "Please select a valid category", Toast.LENGTH_SHORT).show();
}
else{
progressDialog.setMessage("Had added the information into database");
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.show();
String id = ref.push().getKey();
DateFormat format = new SimpleDateFormat("dd-MM-yyyy");
Calendar calendar = Calendar.getInstance();
String date = format.format(calendar.getTime());
Data inform = new Data(categoryGet, date, id, notesGet, Integer.parseInt(amountGet));
ref.child(id).setValue(inform).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if(task.isSuccessful()){
Toast.makeText(MainActivity.this, "Information added successfully", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(MainActivity.this, "Fail to add the information", Toast.LENGTH_SHORT).show();
}
progressDialog.dismiss();
}
});
}
dialog.dismiss();
}
});
cancelButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
dialog.dismiss();
}
});
}
}
MainActivity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffff00"
android:elevation="4dp" />
<TextView
android:id="#+id/totalCashBack"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:text=" Total Cash Back = RM 0"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold" />
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycle_view"
android:layout_width="match_parent"
android:layout_height="556dp" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</LinearLayout>
<Button
android:id="#+id/add_new"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:backgroundTint="#ffff00"
android:text="Add"
app:fabSize="normal" />
</LinearLayout>
InputLayout.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:elevation="10dp"
app:cardElevation="10dp"
android:layout_margin="10dp"
android:orientation="vertical"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#000"
android:layout_margin="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="What did you had spend on ?"
android:gravity="center"
android:textColor="#fff"
android:textStyle="bold"
android:layout_margin="5dp"
android:textSize="20sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Spinner
android:id="#+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#ffff00"
android:entries="#array/category"/>
<EditText
android:id="#+id/insert_amount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Please enter a amount:"
android:textColor="#fff"
android:inputType="number"
android:textColorHint="#fff"/>
<EditText
android:id="#+id/insert_note"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Please enter a note:"
android:textColor="#fff"
android:textColorHint="#fff"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<Button
android:id="#+id/cancel_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Cancel"
android:textAllCaps="false"
android:textColor="#000"
android:textStyle="bold"
android:background="#fff"
android:layout_margin="2dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<Button
android:id="#+id/add_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add Transaction"
android:textAllCaps="false"
android:textColor="#000"
android:textStyle="bold"
android:background="#ffff00"
android:layout_margin="2dp"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
strings.xml
<resources>
<string name="app_name">PracticalAssignment</string>
<string-array name="category">
<item>Select a category</item>
<item>Petrol Spend</item>
<item>Groceries Spend</item>
<item>eWallet Transaction</item>
<item>Other Eligible Spend</item>
</string-array>
</resources>
You have to create an adapter class and add with your recycler view.
The basic snippet to set adapter to recycler view is like bellow
YourAdater adapter = YourAdater();
layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(adapter);
for more detail that how to create a RecyclerView AdapterClass you can see this or this

How do I fix my FirebaseRecyclerAdapter on a fragment?

I am working on this application and I'm trying to show my "expenses" database data in my personal fragment. I have created a recycler view file to replace the default layout. I am struggling to make this work. Can anyone help with the FirebaseRecycler Adapter and the holder class? I am not able to make this work, my fragment display the default layout with no information. I have tried and follow some codes but it is not working.
here is my personal fragment where the recycler view should appear
package uk.brighton.ama75.project;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.TextView;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
import java.time.chrono.JapaneseDate;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
public class personalFragment extends Fragment {
private FirebaseAuth mAuth;
private String currentUserID;
private DatabaseReference databaseReference;
private RecyclerView recyclerView;
private Adapter adapter;
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View myView = inflater.inflate(R.layout.fragment_personal, container, false);
mAuth = FirebaseAuth.getInstance();
currentUserID = mAuth.getCurrentUser().getUid();
databaseReference = FirebaseDatabase.getInstance().getReference().child("Expenses").child(currentUserID);
recyclerView = myView.findViewById(R.id.recycler_expense);
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setStackFromEnd(true);
layoutManager.setReverseLayout(true);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(layoutManager);
return myView;
}
#Override
public void onStart() {
super.onStart();
Query query = FirebaseDatabase.getInstance()
.getReference()
.child("expenses")
.limitToLast(5);
FirebaseRecyclerOptions<PersonalExpenses> options =
new FirebaseRecyclerOptions.Builder<PersonalExpenses>()
.setQuery(query, PersonalExpenses.class)
.build();
FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<PersonalExpenses, MyViewHolder>(options) {
#Override
protected void onBindViewHolder(#NonNull MyViewHolder holder, int position, #NonNull PersonalExpenses model) {
holder.setDate(model.getDate());
holder.setDescription(model.getDescription());
holder.setAmount(model.getAmount());
holder.setType(model.getType());
}
#NonNull
#Override
public MyViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.expense_recycler, parent, false);
return new MyViewHolder(view);
}
};
recyclerView.setAdapter(adapter);
}
#Override
public void onStop() {
super.onStop();
}
public static class MyViewHolder extends RecyclerView.ViewHolder {
private final View mView;
public MyViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
private void setDate(String date) {
TextView mDate = mView.findViewById(R.id.date_income);
mDate.setText(date);
}
private void setType(String type) {
TextView mType = mView.findViewById(R.id.type_txt);
mType.setText(type);
}
private void setDescription(String description) {
TextView mNote = mView.findViewById(R.id.note_txt);
mNote.setText(description);
}
private void setAmount(String amount) {
TextView mAmount = mView.findViewById(R.id.amount_income);
String stramount = String.valueOf(amount);
mAmount.setText(stramount);
}
}
}
This is the expenses recycler view file
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/expense_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="5dp"
app:cardElevation="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:id="#+id/date_income"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="6 June 2019"
android:textAppearance="?android:textAppearanceSmall"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2">
<TextView
android:id="#+id/type_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="Type"
android:textAlignment="center"
android:textAppearance="?android:textAppearanceSmall"
android:textStyle="bold" />
<TextView
android:id="#+id/note_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/type_txt"
android:text="#string/description"
android:textAlignment="center"
android:textAppearance="?android:textAppearanceSmall"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3
">
<TextView
android:id="#+id/amount_income"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="0000"
android:textAlignment="center"
android:textAppearance="?android:textAppearanceSmall"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
This is the personal layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:background="#FFF1F3FC"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
app:cardElevation="5dp"
android:elevation="10dp"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:layout_margin="10dp"
android:layout_height="wrap_content"
tools:ignore="Suspicious0dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="#android:color/black"
android:id="#+id/expenses"
android:text="expense"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_weight="3"
android:gravity="center"
android:layout_margin="10dp"
android:layout_height="wrap_content"
tools:ignore="Suspicious0dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/expense_txt"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="#android:color/black"
android:text="000.00"/>
</RelativeLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:id="#+id/recycler_expense"
android:layout_height="match_parent"/>
</LinearLayout>
I believe you are missing these two main code.
Set adapter.startListening() inside onStart()
Set adapter.stopListening() inside onStop()
Make sure to put the code before the scope end of onStart() as you are performing a lot of operations and setting your adapter above.

Create NavigationDrawer in Fragment, NOT Activity

Would like to know how to create a NavigationDrawer within a Fragment (in this case my HomeFragment) and NOT in an Activity. Have seen everything on how to create a NavigationDrawer within an Activity, such as MainActivity, but my goal for this project is to create a NavigationDrawer ONLY for the HomeFragment. Don't want any of the other fragments to contain it. The drawer_menu will contain Edit Profile, Settings, and Log Out. Below I have posted what I have done... Is there a better way to do it? Code seems to be a bit awkward.
Every video I have seen, every post has been about creating a NavigationDrawer in Activities, so I'm wondering what the code would look like for Fragment. I tried doing it just like you would for Activity, but it wouldn't work.
Below you guys have my HomeFragment.java and fragment_home.xml
fragment_home.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".Fragment.HomeFragment"
tools:openDrawer="start">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar_home_fragment"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?android:attr/windowBackground"
android:elevation="4dp"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/events_logo_main_activity"
android:layout_width="180dp"
android:layout_height="45dp"
android:layout_centerInParent="true"
android:layout_marginTop="10dp"
android:src="#drawable/events_logo_black_max_size" />
<ImageView
android:id="#+id/camera_create_an_event_main_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerInParent="true"
android:layout_marginEnd="11dp"
android:src="#drawable/ic_camera_create_events_home_fragment_black" />
<ImageView
android:id="#+id/three_bars_settings_main_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerInParent="true"
android:src="#drawable/ic_three_bars_settings_home_fragment_black" />
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/bar">
</androidx.recyclerview.widget.RecyclerView>
</LinearLayout>
<ProgressBar
android:id="#+id/progress_circular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/header"
app:itemTextColor="#color/colorPrimaryAqua50"
app:menu="#menu/drawer_menu" />
</androidx.drawerlayout.widget.DrawerLayout>
HomeFragment.java
package com.e.events.Fragment;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.e.events.Adapter.PostAdapter;
import com.e.events.EditProfileActivity;
import com.e.events.MainActivity;
import com.e.events.Model.Post;
import com.e.events.PostActivity;
import com.e.events.R;
import com.google.android.material.navigation.NavigationView;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
import java.util.List;
public class HomeFragment extends Fragment {
private ImageView options;
private DrawerLayout drawer;
ProgressBar progressBar;
private RecyclerView recyclerView;
private PostAdapter postAdapter;
private List<Post> postLists;
private ImageView camera_create_event;
private List<String> followingList;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_home, container, false);
recyclerView = view.findViewById(R.id.recycler_view);
recyclerView.setHasFixedSize(true);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
linearLayoutManager.setReverseLayout(true);
linearLayoutManager.setStackFromEnd(true);
recyclerView.setLayoutManager(linearLayoutManager);
postLists = new ArrayList<>();
postAdapter = new PostAdapter(getContext(), postLists);
recyclerView.setAdapter(postAdapter);
progressBar = view.findViewById(R.id.progress_circular);
options = view.findViewById(R.id.three_bars_settings_main_activity);
options.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
drawer.openDrawer(GravityCompat.START);
}
}
});
Toolbar toolbar = view.findViewById(R.id.toolbar_home_fragment);
drawer = view.findViewById(R.id.drawer_layout);
camera_create_event = view.findViewById(R.id.camera_create_an_event_main_activity);
camera_create_event.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), PostActivity.class);
startActivity(intent);
}
});
checkFollowing();
return view;
}
private void checkFollowing() {
followingList = new ArrayList<>();
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Follow")
.child(FirebaseAuth.getInstance().getCurrentUser().getUid())
.child("following");
reference.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
followingList.clear();
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
followingList.add(snapshot.getKey());
}
readPosts();
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
});
}
private void readPosts() {
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Posts");
reference.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
postLists.clear();
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
Post post = snapshot.getValue(Post.class);
for (String id : followingList) {
if (post.getPublisher().equals(id)) {
postLists.add(post);
}
}
}
postAdapter.notifyDataSetChanged();
progressBar.setVisibility(View.GONE);
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
});
}
}
It's not possible.
Because To implement the Navigation Drawer we first need to add android.support.v4.widget.DrawerLayout as the root of the activity layout.
For Toggle Option of Navigation Drawer, We Require ToolBar.
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar,
R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawerLayout.addDrawerListener(toggle);
The ToolBar is not possible in the fragment.
For Better use, Make Navigation View in Activity inside the DrawerLayout.

make same fab Transformation exapnd behavior like shown at material.io

I wanna have same fab transformation behavior as shown in
Material Website in Full Screen (or morph) section.
I have tried default FabTransformationScrimBehavior and FabTransformationSheetBehavior. but scrim behavior doesn't do anything and sheet behavior don't animate just like I wanted and also it reduce the elevation of the fab to value 0f. and I haven't found any way to unexpand fab. and I wanna know how to use fab transformation behavior. Actually I didn't find any doc on how to use it. So Please help
Code
This is the code that I used:
this is the code of first activity:-
final FloatingActionButton actionButton = findViewById(R.id.add_fab);
actionButton.setOnClickListener(view -> {
actionButton.setExpanded(!actionButton.isExpanded());
});
And this is the xml of first activity:-
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<include layout="#layout/include_generic_toolbar" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/list_rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="76dp"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
tools:listitem="#layout/media_list_item_card" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/add_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:includeFontPadding="false"
android:text="Add Media"
android:textAllCaps="false"
android:visibility="visible"
app:srcCompat="#drawable/ic_add_24"/>
<com.google.android.material.circularreveal.CircularRevealFrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible"
app:layout_behavior="com.google.android.material.transformation.FabTransformationSheetBehavior"
>
<fragment
android:id="#+id/fab_transformation"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.zimong.ssms.fragments.AddMediaFragment"
/>
</com.google.android.material.circularreveal.CircularRevealFrameLayout>
And the code of AddMediaFragment(second screen):-
package com.zimong.ssms.fragments;
import android.app.DatePickerDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.DialogFragment;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.zimong.ssms.R;
import com.zimong.ssms.common.model.User;
import com.zimong.ssms.extended.CallbackHandlerImpl;
import com.zimong.ssms.model.Source;
import com.zimong.ssms.model.ZResponse;
import com.zimong.ssms.service.AppService;
import com.zimong.ssms.service.ServiceLoader;
import com.zimong.ssms.util.Constants;
import com.zimong.ssms.util.Util;
import java.util.Calendar;
import java.util.Date;
import retrofit2.Call;
import retrofit2.Response;
public class AddMediaFragment extends DialogFragment {
private ArrayAdapter<Source> adapter;
private TextView source;
private int checkedItem = 0;
private TextView mediaDate;
private Date currentSelectedDate;
public static AddMediaFragment newInstance() {
AddMediaFragment fragment = new AddMediaFragment();
Bundle bundle = new Bundle();
fragment.setArguments(bundle);
return fragment;
}
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_FRAME, R.style.AppTheme_Light);
setHasOptionsMenu(true);
}
private void getSources() {
final User user = Util.getUser(getActivity());
AppService service = ServiceLoader.createService(AppService.class);
Call<ZResponse> call = service.mediaGallerySources(Constants.DEFAULT_PLATFORM, user.getToken());
call.enqueue(new CallbackHandlerImpl<Source[]>(getActivity(), true, true, Source[].class) {
#Override
protected void failure(Throwable t) {
}
#Override
protected void failure(Response<ZResponse> response) {
}
#Override
protected void success(Source[] response) {
if (response.length > 0) {
source.setText(response[0].getName());
}
adapter = new ArrayAdapter<Source>(getContext(), R.layout.dialog_singlechoice_item, response) {
#Override
public long getItemId(int position) {
return getItem(position).getPk();
}
};
}
});
}
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_add_media, container, false);
TextView headline = view.findViewById(R.id.media_headline);
Toolbar toolbar = view.findViewById(R.id.toolbar);
((AppCompatActivity) getContext()).setSupportActionBar(toolbar);
source = view.findViewById(R.id.source);
mediaDate = view.findViewById(R.id.media_date);
Calendar fromDateInstance = Calendar.getInstance();
currentSelectedDate = fromDateInstance.getTime();
mediaDate.setText(Util.formatDate(fromDateInstance.getTime(), "dd MMM yyyy"));
final DatePickerDialog fromDatePicker = new DatePickerDialog(getContext(), (datePicker, year, month, date) -> {
fromDateInstance.set(Calendar.YEAR, year);
fromDateInstance.set(Calendar.MONTH, month);
fromDateInstance.set(Calendar.DATE, date);
currentSelectedDate = fromDateInstance.getTime();
mediaDate.setText(Util.formatDate(currentSelectedDate, "dd MMM yyyy"));
}, fromDateInstance.get(Calendar.YEAR), fromDateInstance.get(Calendar.MONTH), fromDateInstance.get(Calendar.DATE));
mediaDate.setOnClickListener(v -> fromDatePicker.show());
source.setOnClickListener(v -> alertDialog());
getSources();
return view;
}
#Override
public boolean onOptionsItemSelected(#NonNull MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
getActivity().onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
private void alertDialog() {
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getContext());
builder.setTitle("Source");
builder.setSingleChoiceItems(adapter, checkedItem, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
source.setText(adapter.getItem(which).getName());
checkedItem = which;
dialog.dismiss();
}
});
builder.show();
}
}
And the xml of Add Media is:-
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.circularreveal.coordinatorlayout.CircularRevealCoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/myCoordinatorLayout"
android:layout_width="match_parent"
android:background="#color/white"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$Behavior"
android:theme="#style/AppTheme.AppBarOverlay">
<include layout="#layout/include_toolbar" />
</com.google.android.material.appbar.AppBarLayout>
<include
layout="#layout/content_add_media"
android:layout_width="match_parent"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
android:layout_height="match_parent"/>
</com.google.android.material.circularreveal.coordinatorlayout.CircularRevealCoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.circularreveal.CircularRevealLinearLayout
android:id="#+id/dial"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_gravity="bottom|center_horizontal"
android:visibility="invisible"
android:layout_marginBottom="16dp"
app:layout_anchor="#id/fab"
app:layout_anchorGravity="top|center_horizontal"
android:background="#color/colorPrimary"
app:layout_behavior="com.google.android.material.transformation.FabTransformationSheetBehavior">
<ImageButton
android:id="#+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/back"/>
</com.google.android.material.circularreveal.CircularRevealLinearLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:backgroundTint="#color/colorPrimary"
app:srcCompat="#android:drawable/ic_dialog_email"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
For the FabTransformationSheetBehavior to work, you need to change the isExpanded value.
on change of this value, expand and collapse animation will be called and visibility of the linearlayout and fab button will be handled automatically. Don't change visibility manually as this would block transformation animation.
Use back button to transform back to FAB.
val fab: FloatingActionButton = findViewById<FloatingActionButton>(R.id.fab)
fab.setOnClickListener { fab.isExpanded = !fab.isExpanded } // this sets isExpanded as true
val back = findViewById<ImageButton>(R.id.back)
back.setOnClickListener{ fab.isExpanded = !fab.isExpanded } // this sets isExpanded as false

listview does not update with notifydatasetchanged() call

My Android listview does not update with notifydatasetchanged() call.
The Main Code Activity:
package com.example.jokesbook;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class MainActivity extends Activity {
public final static String EXTRA_MESSAGE = "com.example.jokesbook.MESSAGE";
CustomAdapter Adapter;
ListView lv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
JokeDB.jokesList = new ArrayList<Joke>();
JokeDB.jokesList.add(new Joke("DDD"));
lv = (ListView)findViewById(android.R.id.list);
Adapter= new CustomAdapter(MainActivity.this, R.layout.joke_list_item, JokeDB.jokesList);
lv.setAdapter(Adapter);
}//onCreate
#Override
public void onResume() {
super.onResume(); // Always call the superclass method first
Log.d("jokesbook", "onResume ");
Adapter.notifyDataSetChanged();
}
class CustomAdapter extends ArrayAdapter<Joke>{
Context context;
int layoutResourceId;
ArrayList<Joke> data = null;
private LayoutInflater mInflater;
public CustomAdapter(Context customAdapter, int layoutResourceId, ArrayList<Joke> data) {
super(customAdapter, layoutResourceId, data);
Log.d("jokesbook", "CustomAdapter ");
this.layoutResourceId = layoutResourceId;
this.context = customAdapter;
this.data = data;
this.mInflater = LayoutInflater.from(customAdapter);
}
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
//item_list
convertView = mInflater.inflate(R.layout.joke_list_item, null);
holder = new ViewHolder();
//fill the views
holder.joke = (TextView) convertView.findViewById(R.id.ListTextView1);
convertView.setTag(holder);
}
else {
// Get the ViewHolder back to get fast access to the TextView
// and the ImageView.
holder = (ViewHolder) convertView.getTag();//
}
holder.joke.setText(data.get(position).jokeStr);
return convertView;
}
class ViewHolder {
TextView joke;
}
}
/** Called when the user clicks the Add a new joke button */
public void goNewJoke(View view) {
Intent intent = new Intent(this, New_joke.class);
startActivity(intent);
}
}
Its xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".MainActivity" >
<Button
android:id="#+id/ButtonAboveList"
android:layout_width="500dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:onClick="goNewJoke"
android:text="#string/Add_a_new_joke"/>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
When adding content to JokeDB.jokesList in another activity that its code is:
package com.example.jokesbook;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
public class New_joke extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_joke);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.new_joke, menu);
return true;
}
public void addJoke(View view){
EditText editTextJoke= (EditText)findViewById(R.id.edit_text_jokeToAdd);
JokeDB.jokesList.add(new Joke(editTextJoke.getText().toString()));
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
}
and its XML is:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/green"
android:orientation="vertical"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:paddingTop="3dp"
tools:context=".New_joke" >
<EditText
android:id="#+id/edit_text_jokeToAdd"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_marginBottom="40dp"
android:background="#color/white"
android:hint="#string/edit_message" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal"
tools:context=".New_joke" >
<TextView
android:id="#+id/AuthorText"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:gravity="left"
android:text="#string/Author"
android:textColor="#android:color/white"
android:textSize="25sp" />
<EditText
android:id="#+id/edit_text_Author"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="#color/white"
android:hint="#string/Only_letters_allowed"
android:inputType="textPersonName" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="60dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal"
tools:context=".New_joke" >
<TextView
android:id="#+id/DateText"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:gravity="left"
android:text="#string/Date"
android:textColor="#android:color/white"
android:textSize="25sp" />
<EditText
android:id="#+id/edit_text_Date"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="#color/white"
android:hint="#string/Only_digits_allowed"
android:inputType="number" />
</LinearLayout>
<Button
android:id="#+id/ButtonAboveList"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:onClick="addJoke"
android:text="#string/Add" />
</LinearLayout>
I cannot see the updated list in the main activity eveb though in onResume I used notifydatasetchanged() function.
Try This....
#Override
public void onResume() {
super.onResume(); // Always call the superclass method first
Log.d("jokesbook", "onResume ");
notifyDataSetChanged();
}

Categories

Resources