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 7828105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:12:10+00:00 2026-06-02T10:12:10+00:00

i am using tabWidget. i have a date picker in my child class when

  • 0

i am using tabWidget. i have a date picker in my child class when i go first time from parent class to child class and select date it works fine and when i go again from parent class to child class and select date the app crashes with logcat result “Unable to add window”

it works fine for the first time but not for the next time
code is following

import java.util.Calendar;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
public class PlaceOrder extends Activity {
    public TextView tvDisplayDate,personName,Cname,cAdrress;
    public DatePicker dpResult;
    public Button btnChangeDate;
    Button cancel,submit;
    public int year;
    public int month;
    public int day;
    int requestCode;
    int resultCode;
    Intent data;
    String Name,cName,Title,Address,Phone,Email;
    static final int DATE_DIALOG_ID = 0;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.placeorder);
        personName=(TextView)findViewById(R.id.firstName);
        Cname=(TextView)findViewById(R.id.Cname);
        cAdrress=(TextView)findViewById(R.id.CAddname);
        personName.setText(AccountInfo.fnameNlName);
        Cname.setText(AccountInfo.cName);
        cAdrress.setText(AccountInfo.cAdd);
        setCurrentDateOnView();
        addListenerOnButton();
        final PlaceOrder PO = this;
        cancel=(Button)findViewById(R.id.Cancel);
        cancel.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if(FastPkgMainActivity.fastPackge==1)
                {
                    Intent fastPkgQuote = new Intent(v.getContext(), FastPkgQuote.class);
                    StringBuffer urlString = new StringBuffer();
                    FastPkgQuote parentActivity = (FastPkgQuote)getParent();
                    parentActivity.replaceContentView("fastpkg1", fastPkgQuote);
                }
                else if(FastPkgMainActivity.fastPackge==2)
                {
                    Intent fastpkgQuoteNew = new Intent(v.getContext(), FastPkgQuoteNew.class);
                    StringBuffer urlString = new StringBuffer();
                    FastPkgQuoteNew parentActivity = (FastPkgQuoteNew)getParent();
                    parentActivity.replaceContentView1("fastPkg2", fastpkgQuoteNew);
                }
                // TO*DO Auto-generated method stub
            }
        }
        );
        submit=(Button)findViewById(R.id.Submit);
        submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    Name=AccountInfo.fnameNlName.toString();
                    cName=AccountInfo.cName.toString();
                    Title=AccountInfo.title.toString();
                    Address=AccountInfo.cAdd.toString();
                    Phone=AccountInfo.phno.toString();
                    Email=AccountInfo.E_ID.toString();
                }
                catch (NullPointerException e) {
                    Name=" ";
                    cName=" ";
                    Title=" ";
                    Address=" ";
                    Phone=" ";
                    Email=" ";
                }
                // TODO Auto-generated method stub
                Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
                //String[] recipients = new String[]{
                    "mymail@email.com", "sales@fastpkg.com",
                }
                ;
                emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
                new String[] {
                    "sales@fastpkg.com"
                }
                );
                emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Placing an Order");
                emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "CustomerDetails       " +
                " Name"+":  "+Name+
                "CompanyName:"+"  "+cName+
                "Title :"+Title+
                "Address: "+Address+
                "Phone #: "+Phone+
                "Email :"+Email
                );
                emailIntent.setType("text/plain");
                startActivityForResult(Intent.createChooser(emailIntent, "Send mail client :"),RESULT_OK);
                onActivityResult(requestCode, resultCode, data);
            }
        }
        );
    }
    protected void onActivityResult(int requestCode, int resultCode,
    Intent data) {
        if (requestCode == 0) {
            if (resultCode == RESULT_CANCELED) {
                if(FastPkgMainActivity.fastPackge==1)
                {
                    Intent fastpkgQuote = new Intent();
                    StringBuffer urlString = new StringBuffer();
                    fastpkgQuote.setClass(getParent(), FastPkgQuote.class);
                    FastPkgQuote parentActivity = (FastPkgQuote)getParent();
                    parentActivity.replaceContentView("fastPkg2", fastpkgQuote);
                }
                else if(FastPkgMainActivity.fastPackge==2)
                {
                    Intent fastpkgQuoteNew = new Intent();
                    StringBuffer urlString = new StringBuffer();
                    fastpkgQuoteNew.setClass(getParent(),
                    FastPkgQuoteNew.class);
                    FastPkgQuoteNew parentActivity =
                    (FastPkgQuoteNew)getParent();
                    parentActivity.replaceContentView1("fastPkg2",
                    fastpkgQuoteNew);
                }
            }
            else if(resultCode==RESULT_OK)
            {
                final PlaceOrder pOrder = this;
                Intent intent = new Intent();
                intent.setClass(pOrder, ThnkYouPage.class);
                startActivity(intent);
            }
        }
    }
    // display current date
    public void setCurrentDateOnView() {
        tvDisplayDate = (TextView) findViewById(R.id.tvDate);
        dpResult = (DatePicker) findViewById(R.id.dpResult);
        dpResult.setVisibility(View.INVISIBLE);
        final Calendar c = Calendar.getInstance();
        year = c.get(Calendar.YEAR);
        month = c.get(Calendar.MONTH);
        day = c.get(Calendar.DAY_OF_MONTH);
        // set current date into textview
        tvDisplayDate.setText(new StringBuilder()
        // Month is 0 based, just add 1
        .append(month + 1).append("-").append(day).append("-")
        .append(year).append(" "));
        // set current date into datepicker
        dpResult.init(year, month, day, null);
    }
    public void addListenerOnButton() {
        btnChangeDate = (Button) findViewById(R.id.btnChangeDate);
        btnChangeDate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showDialog(DATE_DIALOG_ID);
            }
        }
        );
    }
    @Override
    public  Dialog onCreateDialog(int id) {
        switch (id) {
            case DATE_DIALOG_ID:
            // set date picker as current date
            return new DatePickerDialog(this.getParent(), datePickerListener, year, month,
            day);
        }
        return null;
    }
    public  DatePickerDialog.OnDateSetListener datePickerListener = new
    DatePickerDialog.OnDateSetListener() {
        // when dialog box is closed, below method will be called.
        public void onDateSet(DatePicker view, int selectedYear,
        int selectedMonth, int selectedDay) {
            year = selectedYear;
            month = selectedMonth;
            day = selectedDay;
            // set selected date into textview
            tvDisplayDate.setText(new StringBuilder().append(month + 1)
            .append("-").append(day).append("-").append(year)
            .append(" "));
            // set selected date into datepicker also
            dpResult.init(year, month, day, null);
        }
    }
    ;
}
  • 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-02T10:12:12+00:00Added an answer on June 2, 2026 at 10:12 am

    In OnCreateDialog method, in the line:

    return new DatePickerDialog(this.getParent(), datePickerListener, year, month,day);
    

    use application basecontext instead of this.getparent()

    it might help you.

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

Sidebar

Related Questions

I have created a custom tabbar in my application (using TabHost and TabWidget ).
I have a little problem using Tabs with Views. First I just copied the
I have 4 tabs that I load using a TabHost and TabWidget using the
I have been looking around on how to customize Android TabWidget using XML with
I'm using Qt and I have a QTabWidget setup in the Qt Designer Editor,
I'm using the depreciated libraries for TabHost/TabWidget in an Ice Cream Sandwich app. I
Using C# for ASP.NET and MOSS development, we often have to embed JavaScript into
When a TabWidget is using intents to designate the target Activity for each tab,
I am using the following code to setup a TabWidget: public void onCreate(Bundle savedInstanceState)
Here is a pruned version of a problem I have using QT/linux. The program

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.