Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8842767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:02:50+00:00 2026-06-14T11:02:50+00:00

I’ve one simple project (API10) with one Edittext and one button in the FragmentActivity.

  • 0

I’ve one simple project (API10) with one Edittext and one button in the “FragmentActivity”.
The main goal is: when I click in the button “Open Dialog” a custom dialog will popup and if I click in “Positive” button, the dialog dismiss and the Edittext (in Fragmentactivity) will show “Positive”… (the same behavior for Negative button).

Everything works fine except when I click to open de Dialog and before I click in the pos/neg button if I rotate the screen, the dialog remains, but, after this rotation, if I click in the Pos/Neg button, nothing happens to the Edittext?!

I’ve created the “applytext” method so that I can find the actual Edittext, but with no success.

can you please help me to understand whats is going on?

(Note: this is a simple example that I made to demonstrate my problem, because I’m using dialogFragment, but I have the same problem behavior).

this Is my code (MainActivity.java):

public class MainActivity extends FragmentActivity {


    private Button bt;
    private EditText et; 



    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);



        bt = (Button) findViewById(R.id.bt_openDialog);
       // et = (EditText) findViewById(R.id.editText_result);


        bt.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                final Dialog d = new Dialog(MainActivity.this, R.style.AppThemeModificado);
                d.requestWindowFeature(Window.FEATURE_NO_TITLE);
                d.setContentView(R.layout.signinlayout);




                Button c = (Button) d.findViewById(R.id.bt_cancelar);

                c.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {



                    //  et.setText("Negative");

                        applytext("Negative");

                        d.dismiss();


                    }
                });


                Button e = (Button) d.findViewById(R.id.bt_entrar);

                e.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {


                    //  et.setText("Positive");
                        applytext("Positive");

                        d.dismiss();

                    }
                });


                WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
                lp.copyFrom(d.getWindow().getAttributes());
                lp.width = WindowManager.LayoutParams.FILL_PARENT;
                //lp.height = WindowManager.LayoutParams.FILL_PARENT;
                d.show();
                d.getWindow().setAttributes(lp);



            }
        });






    }





    private void applytext(String text) {


        Log.d("HugoXp", "----in");

        et = (EditText) findViewById(R.id.editText_result);


        if (et == null) {

            Log.d("HugoXp", "et = null");

        }else{

            Log.d("HugoXp", "et <> null");
            Log.d("HugoXp", "Text that was in the et: " + et.getText().toString());
            Log.d("HugoXp", "actual 'String text': " + text);           
        }



        et.setText(text);


        Log.d("HugoXp", "----out");
    }



    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    }

(the file: signinlayout.xml)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/outrashape"
    android:orientation="vertical" >




    <ImageView
        android:layout_width="match_parent"
        android:layout_height="64dp"
        android:background="#FFFFBB33"
        android:contentDescription="@string/app_name"
        android:scaleType="center"
        android:src="@drawable/logoheader" />


    <EditText
        android:id="@+id/username"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="4dp"
        android:layout_marginLeft="4dp"
        android:layout_marginRight="4dp"
        android:layout_marginTop="16dp"
        android:hint="@string/username"
        android:inputType="textEmailAddress" />



    <EditText
        android:id="@+id/password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:layout_marginLeft="4dp"
        android:layout_marginRight="4dp"
        android:layout_marginTop="4dp"
        android:hint="@string/password"
        android:inputType="textPassword"
        android:typeface="serif" />






    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Applied theme"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >








        <Button
            android:id="@+id/bt_entrar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="50"
            android:background="@drawable/estilobotaored"
            android:text="Positive" />






        <Button
            android:id="@+id/bt_cancelar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="50"
            android:background="@drawable/estilobotaored"
            android:text="Negative" />

    </LinearLayout>

</LinearLayout>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:02:52+00:00Added an answer on June 14, 2026 at 11:02 am

    You might consider using Android AlertDialog Fragment. It’s slightly less flexible in some respects, but seems to do exactly what you need to here. Although, this is not where your problem lies.

    Either way, you will create your dialog by doing something like this(either in a seperate file or in the same activity, doesnt matter)

    public static class MyAlertDialogFragment extends DialogFragment {
    
    public static MyAlertDialogFragment newInstance(int title) {
        MyAlertDialogFragment frag = new MyAlertDialogFragment();
        Bundle args = new Bundle();
        args.putInt("title", title);
        frag.setArguments(args);
        return frag;
    }
    
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        int title = getArguments().getInt("title");
    
        return new AlertDialog.Builder(getActivity())
                .setIcon(R.drawable.alert_dialog_icon)
                .setTitle(title)
                .setPositiveButton(R.string.alert_dialog_ok,
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            ((FragmentAlertDialog)getActivity()).doPositiveClick();
                        }
                    }
                )
                .setNegativeButton(R.string.alert_dialog_cancel,
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            ((FragmentAlertDialog)getActivity()).doNegativeClick();
                        }
                    }
                )
                .create();
        }
    }
    

    Then, from the calling activity, you can use these callback methods:

    void showDialog() 
    {
            DialogFragment newFragment = MyAlertDialogFragment.newInstance(
            "Title");
            newFragment.show(getFragmentManager(), "dialog");
    }
    
    public void doPositiveClick() {
    
        Log.i("FragmentAlertDialog", "Positive click!");
        editText.setText("positive");
    }
    
    public void doNegativeClick() {
        // Do stuff here.
        Log.i("FragmentAlertDialog", "Negative click!");
        editText.setText("negative");
    }
    

    So in your buttons onClick(), you will simply call showDialog(), and the rest should work as expected

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I have just tried to save a simple *.rtf file with some websites and
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
I need a function that will clean a strings' special characters. I do NOT
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.