Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to create activity as a dialog?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 361
    Comment on it

    We know that Alert dialog boxes are used to show some popup to user so that user can perform some action. But with Activity dialog you can manage the visibility of dialog based on activity life cycles.

    To create an activity as a dilaog we have to set theme for that activity in manifest file like this :

    <activity android:theme="@android:style/Theme.Dialog" />

     

    // and in your Activity you can show your activity dialog as :

    public class BaseActivity extends Activity {
    
        Button btnClick;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            btnClick = (Button) findViewById(R.id.btnClick);
            btnClick.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(BaseActivity.this, ActivityDialog.class);
                    startActivity(intent);
                }
            });
        }
    
    }

     

    and your Activity Dialog class is :

    public class ActivityDialog extends Activity implements OnClickListener {
    
        Button btnCancel;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
    
            super.onCreate(savedInstanceState);
    
            setContentView(R.layout.activity_dialog);
    
    
            btnCancel_btn = (Button) findViewById(R.id.cancel_btn_id);
    
           btnCancel.setOnClickListener(this);
        }
    
       @Override
        public void onClick(View v) {
    
            switch (v.getId()) {
            case R.id.cancel_btn_id:
    
            Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT)
                    .show();
                this.finish();
                break;
            }
        }

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: