You are on page 1of 30

N01346254 Inderjit Singh

Output:
Saving first note:
Note Saved:
Saving another note:
Notes list:
Saving more notes:
Now closing the application:
Re-running the application:
We get all the saved notes:
Editing the third note:
Note list updated:
Again closing the app:
Re-running the app:
We get the saved list (updated)
For saving data in shared preferences: (On Save button click)
int length=DummyContent.ITEMS.size();
SharedPreferences preferences =
getSharedPreferences("Sharedpreferences",MODE_PRIVATE);
SharedPreferences.Editor editor=preferences.edit();
// editor.putString("EDITED TEXT",text);
editor.putInt("NOTES LENGTH",length);
editor.apply();

////------For note details


et_desc= findViewById(R.id.ET_Description_Notes);
sharedNoteDetails.description=et_desc.getText().toString();
Gson gson = new Gson();
String jsonText=gson.toJson(sharedNoteDetails);
//data object will be stored in the form of string
Log.d("shared", "saveClicked: "+jsonText);

int arraySize= Integer.parseInt(id_TV.getText().toString())+1;


SharedPreferences[] detailsPreferences=new SharedPreferences[arraySize];
for(int i=1;i<=arraySize;i++)
{
if(Integer.parseInt(id_TV.getText().toString()) ==i)
{
detailsPreferences[i] = getSharedPreferences("sharedDetailsNote"+i,
Context.MODE_PRIVATE);
SharedPreferences.Editor detailsEditor = detailsPreferences[i].edit();
// editor.putString("EDITED TEXT",text);
detailsEditor.putString("NOTE DATA" + i, jsonText);
detailsEditor.apply();
}}
On load activity code:(getting saved data from shared preferences)
for(int i=1;i<=notesLength;i++) {
if(position ==i)
{
SharedPreferences detailsPreferences =
con.getSharedPreferences("sharedDetailsNote"+i, MODE_PRIVATE);
String jsonText = detailsPreferences.getString("NOTE DATA"+ i, "");
if (jsonText.length() > 0) {
Gson gson = new Gson();
sharedNoteDetails = gson.fromJson(jsonText,
SharedPreferrencesNoteDetails.class);
noteDescription = sharedNoteDetails.description;
}
}}
Complete Source code (java and xml files):
Note Details.java
package com.inderjit.androidassessment2;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import com.google.gson.Gson;
import com.inderjit.androidassessment2.dummy.DummyContent;

import java.text.SimpleDateFormat;
import java.util.Date;

public class NoteDetails extends AppCompatActivity {

TextView id_TV;
int position;

EditText descNote,et_desc;
//for default constructor
SharedPreferrencesNoteDetails sharedNoteDetails = new
SharedPreferrencesNoteDetails();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_note_details);
id_TV = findViewById(R.id.ET_ID_notes);
Intent intent = getIntent();

if(intent.hasExtra("note_position"))
{

position = intent.getIntExtra("note_position",0);
id_TV.setText(DummyContent.ITEMS.get(position).id);

((TextView)findViewById(R.id.ET_Description_Notes)).setText(DummyContent.ITEMS.get(po
sition).content);

}
else if(intent.hasExtra("note_time"))
{
String currentTime = intent.getStringExtra("note_time");
String noteNumber = "" + (DummyContent.ITEMS.size()+1);
id_TV.setText(noteNumber);
((TextView)findViewById(R.id.ET_Description_Notes)).setText("New
Note.....");
}

public void saveOnClick(View view) {


/////
/*
Previous code

if(Integer.parseInt(id_TV.getText().toString())<=(DummyContent.ITEMS.size())) {
EditText currentDescription = (EditText)
findViewById(R.id.ET_Description_Notes);
String description = currentDescription.getText().toString();
DummyContent.ITEMS.get(position).content = description;
finish();
}
else
{
Intent intent = getIntent();
String currentTime = intent.getStringExtra("note_time");
EditText currentDescription = (EditText)
findViewById(R.id.ET_Description_Notes);
String description = currentDescription.getText().toString();
description+="\nCreated on :" +currentTime;

DummyContent.addNewItem(description,Integer.parseInt(id_TV.getText().toString()+1));
finish();
}
*/
///New code begins

if(Integer.parseInt(id_TV.getText().toString())<=(DummyContent.ITEMS.size()))
{
EditText currentDescription = (EditText)
findViewById(R.id.ET_Description_Notes);
String description = currentDescription.getText().toString();
DummyContent.ITEMS.get(position).content = description;
finish();
}
else
{
Intent intent = getIntent();
String currentTime = intent.getStringExtra("note_time");
EditText currentDescription = (EditText)
findViewById(R.id.ET_Description_Notes);
String description = currentDescription.getText().toString();
//description+="\nCreated on :" +currentTime;

DummyContent.addNewItem(description,Integer.parseInt(id_TV.getText().toString()+1));
finish();
}

////new code starts


int length=DummyContent.ITEMS.size();
SharedPreferences preferences =
getSharedPreferences("Sharedpreferences",MODE_PRIVATE);
SharedPreferences.Editor editor=preferences.edit();
// editor.putString("EDITED TEXT",text);
editor.putInt("NOTES LENGTH",length);
editor.apply();

////------For note details


et_desc= findViewById(R.id.ET_Description_Notes);
sharedNoteDetails.description=et_desc.getText().toString();
Gson gson = new Gson();
String jsonText=gson.toJson(sharedNoteDetails);
//data object will be stored in the form of string
Log.d("shared", "saveClicked: "+jsonText);

int arraySize= Integer.parseInt(id_TV.getText().toString())+1;


SharedPreferences[] detailsPreferences=new SharedPreferences[arraySize];
for(int i=1;i<=arraySize;i++)
{
if(Integer.parseInt(id_TV.getText().toString()) ==i)
{
detailsPreferences[i] = getSharedPreferences("sharedDetailsNote"+i,
Context.MODE_PRIVATE);
SharedPreferences.Editor detailsEditor =
detailsPreferences[i].edit();
// editor.putString("EDITED TEXT",text);
detailsEditor.putString("NOTE DATA" + i, jsonText);
detailsEditor.apply();
}
}
////new code finishes

public void cancelOnClick(View view) {


finish();
}
}
MainActivity.java
package com.inderjit.androidassessment2;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.inderjit.androidassessment2.dummy.DummyContent;

import java.text.SimpleDateFormat;
import java.util.Date;
import com.google.gson.Gson;
import android.content.Intent;
import android.content.SharedPreferences;
public class MainActivity extends AppCompatActivity implements
NoteFragment.MyNotesOnClickListener {

TextView id_TV;
int position;

SharedPreferrencesNoteDetails sharedNoteDetails ;
EditText descNote;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
NoteFragment notes = new NoteFragment();
getSupportFragmentManager()
.beginTransaction()
.add(R.id.fragment_notes,notes,"notesFragment")
.commit();

//added code
onloadData(this);

/*
//added code for notes description
descNote = findViewById(R.id.ET_Description_Notes);
//load the shared data and populate in Et variable
SharedPreferences preferences = getPreferences(MODE_PRIVATE);
String jsonText= preferences.getString("NOTE DATA","");
if(jsonText.length()>0)
{
Gson gson = new Gson();
sharedNoteDetails=
gson.fromJson(jsonText,SharedPreferrencesNoteDetails.class);
descNote.setText(sharedNoteDetails.description);

}
*/
}

//added method
private void onloadData(Context con)
{
DummyContent.loadData(con);
}
@Override
public void onClick(int position) {
Toast.makeText(this, "Selected Note : "+ DummyContent.ITEMS.get(position),
Toast.LENGTH_SHORT).show();
Intent intent = new Intent(this,NoteDetails.class);
intent.putExtra("note_position" ,position);
// startActivity(intent);
startActivityForResult(intent, 1000);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent
data) {
super.onActivityResult(requestCode, resultCode, data);
// Toast.makeText(this, "Changes saved", Toast.LENGTH_SHORT).show();
NoteFragment notesFragment= (NoteFragment)
getSupportFragmentManager().findFragmentByTag("notesFragment");
if(notesFragment!=null)
notesFragment.refresh();
Toast.makeText(this, "Changes saved", Toast.LENGTH_SHORT).show();
}

public void AddOnClick(View view) {


SimpleDateFormat time = new SimpleDateFormat("dd/MM/YYYY hh.mm aa");
String currentTime= time.format(new Date());
Toast.makeText(this, "New Note : ", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(this,NoteDetails.class);
intent.putExtra("note_time" ,currentTime);
// startActivity(intent);
startActivityForResult(intent, 1000);
}
}
DummyContent.java
package com.inderjit.androidassessment2.dummy;

import android.content.Context;
import android.content.SharedPreferences;

import com.google.gson.Gson;
import com.inderjit.androidassessment2.R;
import com.inderjit.androidassessment2.SharedPreferrencesNoteDetails;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.content.SharedPreferences;
import android.widget.EditText;

import com.google.gson.Gson;

import static android.content.Context.MODE_PRIVATE;

/**
* Helper class for providing sample content for user interfaces created by
* Android template wizards.
* <p>
* TODO: Replace all uses of this class before publishing your app.
*/
public class DummyContent {

/**
* An array of sample (dummy) items.
*/
public static final List<DummyItem> ITEMS = new ArrayList<DummyItem>();

/**
* A map of sample (dummy) items, by ID.
*/
public static final Map<String, DummyItem> ITEM_MAP = new HashMap<String,
DummyItem>();

private static int COUNT=0;

public static SharedPreferrencesNoteDetails lengthSize ;

public static SharedPreferrencesNoteDetails sharedNoteDetails ;


public static EditText descNote;
static int notesLength;
/* static {
// Add some sample items.
for (int i = 1; i <= COUNT; i++) {
addItem(createDummyItem(i));
}
}*/

private static void addItem(DummyItem item) {


ITEMS.add(item);
ITEM_MAP.put(item.id, item);
}

//previous createDummyItem code


/*
private static DummyItem createDummyItem(int position) {

return new DummyItem(String.valueOf(position), "My Notes " + position,


makeDetails(position));

}
*/

/// added new createDummyItem code


private static DummyItem createDummyItem(int position,Context context) {

String noteDescription="My note";


//added code for notes description
Context con=context;
//load the shared data and populate in Et variable
for(int i=1;i<=notesLength;i++)
{
if(position ==i)
{
SharedPreferences detailsPreferences =
con.getSharedPreferences("sharedDetailsNote"+i, MODE_PRIVATE);
String jsonText = detailsPreferences.getString("NOTE DATA"+ i,
"");
if (jsonText.length() > 0) {
Gson gson = new Gson();
sharedNoteDetails = gson.fromJson(jsonText,
SharedPreferrencesNoteDetails.class);
noteDescription = sharedNoteDetails.description;
}
}
}

return new DummyItem(String.valueOf(position), "" + noteDescription,


makeDetails(position));
}

private static String makeDetails(int position) {


StringBuilder builder = new StringBuilder();
builder.append("Details about Item: ").append(position);
for (int i = 0; i < position; i++) {
builder.append("\nMore details information here.");
}
return builder.toString();
}

////added method
public static void loadData(Context con)
{
SharedPreferences preferences =
con.getSharedPreferences("Sharedpreferences",Context.MODE_PRIVATE);
notesLength= preferences.getInt("NOTES LENGTH",0);
for (int i = 1; i <= notesLength; i++) {
addItem(createDummyItem(i,con));
}
}

/**
* A dummy item representing a piece of content.
*/
public static class DummyItem {
public final String id;
public String content;
public final String details;

public DummyItem(String id, String content, String details) {


this.id = id;
this.content = content;
this.details = details;

}
@Override
public String toString() {
return content;
}
}

////
private static DummyItem createNewItem(String content,int position) {
return new DummyItem(String.valueOf(position), content + "",
makeDetails(position));

}
/////
public static void addNewItem(String desc,int i)
{
addItem(createNewItem(desc,COUNT+1));
COUNT=COUNT+1;
}
}
SharedPreferencesNoteDetails.java
package com.inderjit.androidassessment2;

public class SharedPreferrencesNoteDetails {

String id;
public String description;
int notesLength;

public SharedPreferrencesNoteDetails(String id, String description) {


this.id = id;
this.description = description;
}

public SharedPreferrencesNoteDetails(int length) {


this.notesLength=length;
}
public SharedPreferrencesNoteDetails() {

@Override
public String toString() {
return "Note{" +
"id='" + id + '\'' +
", description='" + description + '\'' +

'}';
}

public String getId() {


return id;
}

public void setId(String id) {


this.id = id;
}

public int getLength() {


return notesLength;
}

public void setLength(int length) {


this.notesLength = length;
}

public String getDescription() {


return description;
}
public void setDescription(String description) {
this.description = description;
}

MynoteRecyclerViewAdapter.java
package com.inderjit.androidassessment2;

import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.inderjit.androidassessment2.dummy.DummyContent.DummyItem;

import java.util.List;

/**
* {@link RecyclerView.Adapter} that can display a {@link DummyItem}.
* TODO: Replace the implementation with code for your data type.
*/
public class MynoteRecyclerViewAdapter extends
RecyclerView.Adapter<MynoteRecyclerViewAdapter.ViewHolder> {

private final List<DummyItem> mValues;

//listener
NoteFragment.MyNotesOnClickListener myNotesListener;

public MynoteRecyclerViewAdapter(List<DummyItem> items,


NoteFragment.MyNotesOnClickListener myNotesListener) {
mValues = items;
this.myNotesListener=myNotesListener;
}

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.fragment_note, parent, false);
return new ViewHolder(view);
}

@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
holder.mItem = mValues.get(position);
holder.mIdView.setText(mValues.get(position).id);
holder.mContentView.setText(mValues.get(position).content);
//setting on click listener to edit button
holder.edit_Button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//referencing the method of interface
myNotesListener.onClick(position);
}
});
}

@Override
public int getItemCount() {
return mValues.size();
}

public class ViewHolder extends RecyclerView.ViewHolder {


public final View mView;
public final TextView mIdView;
public final TextView mContentView;
public DummyItem mItem;

//adding edit button


public Button edit_Button;

public ViewHolder(View view) {


super(view);
mView = view;
mIdView = (TextView) view.findViewById(R.id.item_number);
mContentView = (TextView) view.findViewById(R.id.content);

//adding fucntionality to edit button..reference


edit_Button= view.findViewById(R.id.btn_edit);

@Override
public String toString() {
return super.toString() + " '" + mContentView.getText() + "'";
}
}
}
NoteFragment.java
package com.inderjit.androidassessment2;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.inderjit.androidassessment2.dummy.DummyContent;

/**
* A fragment representing a list of Items.
*/
public class NoteFragment extends Fragment {

// TODO: Customize parameter argument names


private static final String ARG_COLUMN_COUNT = "column-count";
// TODO: Customize parameters
private int mColumnCount = 1;

MyNotesOnClickListener myNotesListener;
MynoteRecyclerViewAdapter adapter;

/**
* Mandatory empty constructor for the fragment manager to instantiate the
* fragment (e.g. upon screen orientation changes).
*/
public NoteFragment() {
}

// TODO: Customize parameter initialization


@SuppressWarnings("unused")
public static NoteFragment newInstance(int columnCount) {
NoteFragment fragment = new NoteFragment();
Bundle args = new Bundle();
args.putInt(ARG_COLUMN_COUNT, columnCount);
fragment.setArguments(args);
return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

if (getArguments() != null) {
mColumnCount = getArguments().getInt(ARG_COLUMN_COUNT);
}
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_notes_list, container, false);

// Set the adapter


if (view instanceof RecyclerView) {
Context context = view.getContext();
RecyclerView recyclerView = (RecyclerView) view;
if (mColumnCount <= 1) {
recyclerView.setLayoutManager(new LinearLayoutManager(context));
} else {
recyclerView.setLayoutManager(new GridLayoutManager(context,
mColumnCount));
}

// recyclerView.setAdapter(new
MynoteRecyclerViewAdapter(DummyContent.ITEMS,myNotesListener));
adapter= new
MynoteRecyclerViewAdapter(DummyContent.ITEMS,myNotesListener);
recyclerView.setAdapter(adapter);
}
return view;
}

void refresh()
{
adapter.notifyDataSetChanged();
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
myNotesListener = (MyNotesOnClickListener) context;
}

interface MyNotesOnClickListener{
void onClick(int position);

}
}
activity_note_details.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".NoteDetails">
<TextView
android:layout_marginTop="100dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/TV_Title"
android:layout_marginBottom="30dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:text="My Note Details"
android:textColor="#000000"
android:textSize="40sp"
/>
<TextView
android:id="@+id/TV_Title"
android:layout_marginTop="200dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/ET_ID_notes"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:text="Note Number"
android:textColor="#000000"
android:textSize="25sp"
/>
<TextView
android:id="@+id/ET_ID_notes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:textSize="20sp"
app:layout_constraintTop_toBottomOf="@id/TV_Title"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:hint="Note ID"
/>
<TextView
android:layout_height="wrap_content"
android:height="1dp"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
app:layout_constraintTop_toBottomOf="@id/ET_ID_notes"
android:background="#a4c639"
/>

<TextView
android:id="@+id/TV_Content"
android:layout_marginTop="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/ET_ID_notes"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:textColor="#000000"
android:text="Description :"
android:textSize="25sp"
/>
<EditText
android:id="@+id/ET_Description_Notes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_marginTop="20dp"
app:layout_constraintTop_toBottomOf="@id/TV_Content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:hint="Note-Content"
/>
<TextView
android:layout_height="wrap_content"
android:height="1dp"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
app:layout_constraintTop_toBottomOf="@id/ET_Description_Notes"
android:background="#a4c639"
/>

<Button
android:id="@+id/btn_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/ET_Description_Notes"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="24dp"
android:background="@drawable/add_btn_layout"
android:onClick="saveOnClick"
android:text="Save"

/>

<Button
android:id="@+id/btn_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/btn_save"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="24dp"
android:background="@drawable/add_btn_layout"
android:onClick="cancelOnClick"
android:text="Cancel"

/>
</androidx.constraintlayout.widget.ConstraintLayout>

fragment_note.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"

android:orientation="horizontal">

<TextView
android:id="@+id/item_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_margin="20dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:textAppearance="?attr/textAppearanceListItem" />

<TextView
android:layout_height="wrap_content"
android:height="1dp"
android:layout_width="match_parent"
app:layout_constraintTop_toBottomOf="@id/content"
android:background="#a4c639"
/>
<TextView
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="200dp"
android:layout_marginLeft="30dp"
android:layout_margin="20dp"
android:hint="Content Tv"
app:layout_constraintLeft_toRightOf="@id/item_number"
app:layout_constraintTop_toTopOf="parent"
android:textAppearance="?attr/textAppearanceListItem" />
<Button
android:id="@+id/btn_edit"
android:text="Edit"
android:minHeight="30dp"
android:minWidth="50dp"
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:background="@drawable/add_btn_layout"
android:textColor="#FF0000"
app:layout_constraintLeft_toRightOf="@id/content"
/>
</androidx.constraintlayout.widget.ConstraintLayout>

fragment_note_list.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView
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/list"
android:name="com.inderjit.androidassessment2.noteFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
app:layoutManager="LinearLayoutManager"
tools:context=".NoteFragment"
tools:listitem="@layout/fragment_note" />

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<Button
android:id="@+id/Add_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:text="+"
android:background="@drawable/add_btn_layout"
android:textSize="30sp"
android:gravity="center"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_margin="20dp"
android:onClick="AddOnClick"
/>
<FrameLayout
android:layout_marginTop="30dp"
android:id="@+id/fragment_notes"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>

You might also like