Custom Dialog + Sending Information to Activity - Android Studio Tutorial

Coding in Flow · 256K views · 2017 · 12:50

Open on YouTube

Software (other)Software practice, open source & careerstutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it when they need a worked example of a custom DialogFragment that returns data to an Activity, and they often come back with follow-up questions about adapting it to adapters or plain Dialog classes.

Recommended by 2 people across 2 different months, 2018 to 2021.

What it is

A 13-minute Android Studio tutorial from Coding in Flow that builds a custom DialogFragment with two EditText fields and OK/Cancel buttons. It shows how to pass the entered values back to the host Activity through an interface that the Activity implements as a listener.

What people said

Recommends Kiran · 2019-06 · Stack Overflow · on “Getting data from database and displaying it in a dialogue box”

Cursor c = db.rawQuery("SELECT * FROM TABLE_NAME", null); while(c.moveToNext()){ int id = c.getInt(0); String title = c.getString(1); String body = c.getString(2); String bodyTranslated = c.getString(3); } This above code shows that the data is fetched from database and the cursor object is used to get the data and show it on the screen. If you have problem with showing data in the AlertDialog check this link: Custom Dialog + Sending Information to Activity - Android Studio Tutorial [this video] For RecyclerView related issues check this link: RecyclerView + CardView - Part 1 - LAYOUTS AND CUSTOM OBJECTS - Android Studio Tutorial [LINK]

Recommends Allicnam · 2021-07 · Stack Overflow · on “Android studio Alert dialog block spaces for input in text”

I find this more difficult than working on an XML file. You could (and probably should) create custom dialogs that have their own view/XML file. To do this, extend DialogFragment: public class MyDialog extends DialogFragment { EditText editText; @Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // get your custom layout LayoutInflater inflater = getActivity().getLayoutInflater(); View view = inflater.inflate(R.layout.my_custom_layout, null); builder.setView(view).setCancelable(false); editText = view.findViewById(R.id.editText); // add your code here } } XML (R.layout.my_custom_layout): <?xml ve

Cites Varun Govind · 2018-08 · Stack Overflow · on “How to set up a custom listener in a custom dialog for android?”

I'm currently having trouble setting up my custom listener. I just want to pass a string from my dialog to my fragment (where I set up the dialog). I was trying to follow this tutorial: [this video] . At minute 10:38, he sets up the listener. This only problem is that in this, he uses DialogFragment, but I'm extending dialog and I don't know how to attach the context to the listener. I've tried to set it up in onAttachedToWindow() and in the dialog constructor but it crashes. What should I actually do? I'd also appreciate it if someone could explain what the difference is between: onAttachedToWindow() vs. onAttach(Context context). Thanks! MY CUSTOM DIALOG BOX: public class NewListDialog extends

Cites Wazy · 2019-05 · Stack Overflow · on “Using Custom Diaglogs in a recycler view”

I am attempting to have it so when a user taps on a post a custom dialog pops up asking if the user is sure they would like to advance to the next screen I am following CodingInFlows [this video] Video on how to implement this The issue I am dealing with is in my recycler adapter I am unable to use the getSupportFragmentManager (8:24 in the video) after playing around I think that the issue is according to this post [LINK] that I am not extending fragment manager but I don't see how I am able to do that since it is a recycler adapter adapter @Override public void onBindViewHolder(@NonNull final ViewHolder holder, int position) { ... holder.parentLayout.setOnClickListener(new View.OnClickListener(

Cites Daniëlle · 2020-03 · Stack Overflow · on “How to call getSupportFragmentManager() from adapter class (which doesn't extend AppCompatActivity)?”

I want to make a dialog that pops up if you click on a Name TextView in my ListView. So I've been following this youtube tutorial: [this video] and he makes a dialog that pops up from his MainActivity. But I want to pop it up from my ListView, so from my Adapter. Because of that I can't call getSupportFragmentManager() . I think it's because my Adapter does extend ArrayAdapter<> instead of AppCompatActivity. Can anyone help me? It goes wrong when I say: changeNameDialog.show(getSupportFragmetnManager(), "Change Name Dialog"); public class PlayersAdapter extends ArrayAdapter<Player> { Tournament tournament = new Tournament(); private LayoutInflater Inflater; public PlayersAdapter(@NonNull Context