I have a list of videos the user has recorded in my app. When the user long-clicks on a video's name in a ListView, a dialog pops up to give the user the options: Play, Rename, Delete. Play brings up a chooser for a video player to play the video. Works as it should. Delete brings up another dialog for confirmation that user wants to delete the video. Also works as it should. When Rename is clicked, it's supposed to show another AlertDialog containing an EditText from a custom view to let the user rename the video.
Here's the XML for the custom view set for the renaming AlertDialog:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/flRename"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText
android:id="@+id/etRename"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_rename" />
</FrameLayout>
In onCreate, I setup the custom view and the AlertDialog:
vRename = getLayoutInflater().inflate(R.layout.rename, null);
etRename = (EditText)vRename.findViewById(R.id.etRename);
adRename = new AlertDialog.Builder(context)
.setIcon(R.drawable.ic_launcher)
.setMessage("Rename video:")
.setPositiveButton("Rename", dioclRename)
.setNegativeButton("Cancel", null)
.setTitle(getString(R.string.app_name))
.setView(vRename)
.create();
When the AlertDialog shows up, it has the icon, title, message and buttons, but not the custom view.
From the AlertDialog documentation:
If you want to display a more complex view, look up the FrameLayout called "custom" and add your view to it:
FrameLayout fl = (FrameLayout) findViewById(android.R.id.custom); fl.addView(myView, new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
so maybe call:
FrameLayout fl = (FrameLayout) adRename.findViewById(android.R.id.custom);
fl.addView(vRename, new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
or check if switching from create() to show() helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With