Reputation: 139
After opening notes I see textview of my note's title and content. I want to edit notes. But there is a problem with the edit note activity. It shows only the text of title in edittext. But below this content text not shown. I tried many ways like I tried to check what's a problem I put data of title. But it is also not showing the title. Means upper title edit text can show title data and content data but second edit text doesn't show title data and content data.
This is notes_open.class
public class notes_open extends AppCompatActivity {
Intent data;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notes_open);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
data= getIntent();
TextView MyTitle = findViewById(R.id.notesopentitle);
TextView MyContent= findViewById(R.id.notesopencontent);
MyContent.setMovementMethod(new ScrollingMovementMethod());
MyTitle.setText(data.getStringExtra("ourtitle"));
MyContent.setText(data.getStringExtra("ourcontent"));
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater= getMenuInflater();
getMenuInflater().inflate(R.menu.notesopen, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch(item.getItemId()){
case android.R.id.home:
onBackPressed();
case R.id.edit_note:
Intent i = new Intent(getApplication(),edit_note.class);
i.putExtra("ourtitle",data.getStringExtra("ourtitle"));
i.putExtra("ourcontent",data.getStringExtra("ourcontent"));
startActivity(i);
}
return super.onOptionsItemSelected(item);
}
}
Below is edit_note.class
public class edit_note extends AppCompatActivity {
Intent data;
EditText edit_title, edit_note;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_note);
data = getIntent();
edit_title = findViewById(R.id.edit_ttile);
edit_note = findViewById(R.id.edit_note);
String edititle = data.getStringExtra("ourtitle");
String editcontent = data.getStringExtra("ourcontent");
try {
edit_title.setText(edititle);
edit_note.setText(editcontent);
}catch (NullPointerException ignore){}
}
}
Edit note 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=".edit_note">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
tools:ignore="MissingConstraints">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</com.google.android.material.appbar.AppBarLayout>
<EditText
android:id="@+id/edit_ttile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:hint="Title"
android:layout_below="@id/appBarLayout2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="56dp" />
<EditText
android:id="@+id/edit_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:hint="Content"
android:layout_below="@id/edit_ttile"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="56dp" />
</RelativeLayout>
Upvotes: 1
Views: 290
Reputation: 6919
Your edittext assigning is wrong :
edit_note = findViewById(R.id.edit_note);
Instead it needs :
edit_note = findViewById(R.id.edit_content);
Upvotes: 2