/** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mailbox);

    Calendar cal = new GregorianCalendar();
    int month = cal.get(Calendar.MONTH);
    System.out.println("Month is:" + month);
    int year = cal.get(Calendar.YEAR);

    int day = cal.get(Calendar.DAY_OF_MONTH);
    curtimestamp = (int) (cal.getTimeInMillis() / 1000L);

    System.out.println("Time In Millis:" + curtimestamp);

    sdate = (+day + "-" + (month + 1) + "-" + year);

    data = new DataBaseHelper(this);

    logout = (TextView) findViewById(R.id.logout);
    welcome = (TextView) findViewById(R.id.welcome);
    newmail = (TextView) findViewById(R.id.newmail);
    inbox = (TextView) findViewById(R.id.inbox);
    sent = (TextView) findViewById(R.id.sent);

    Bundle bundle = getIntent().getExtras();
    cmpltname = bundle.getString("wel");
    onlyname = bundle.getString("welcome");

    tbl2 = (TableLayout) findViewById(R.id.mail_table2);
    tbl2.setBackgroundResource(R.layout.shapes);

    tbl3 = (TableLayout) findViewById(R.id.mail_table3);
    tbl3.setBackgroundResource(R.layout.shapes);
    tbl3.setVisibility(View.GONE);

    welcome.setText("Welcome" + " " + cmpltname);

    newmail.setOnClickListener(
        new TextView.OnClickListener() {
          public void onClick(View v) {
            myDialog = new Dialog(mailbox.this);
            myDialog.setContentView(R.layout.newmail);
            myDialog.setTitle("Compose Mail");
            myDialog.setCancelable(true);

            final TextView from = (TextView) myDialog.findViewById(R.id.txtfrom);
            final TextView date = (TextView) myDialog.findViewById(R.id.txtdate);
            final EditText to = (EditText) myDialog.findViewById(R.id.editto);
            final EditText sub = (EditText) myDialog.findViewById(R.id.editsub);
            final EditText body = (EditText) myDialog.findViewById(R.id.editbody);
            final EditText att = (EditText) myDialog.findViewById(R.id.editatt);
            Button button = (Button) myDialog.findViewById(R.id.btnsend);

            from.setText(onlyname);
            date.setText(sdate);
            button.setOnClickListener(
                new OnClickListener() {
                  public void onClick(View v) {

                    String from3 = from.getText().toString();
                    System.out.println("from:" + from3);
                    String date3 = date.getText().toString();
                    System.out.println("date:" + date3);
                    String to3 = to.getText().toString();
                    System.out.println("to:" + to3);
                    String sub3 = sub.getText().toString();
                    System.out.println("title:" + sub3);
                    String body3 = body.getText().toString();
                    System.out.println("body:" + body3);
                    String att3 = att.getText().toString();
                    System.out.println("att:" + att3);
                    String status = "N";

                    data.Insertmailboxto(onlyname, from3, to3, date3, att3, sub3, body3, status);

                    Toast.makeText(mailbox.this, "Message Sent Successfully", Toast.LENGTH_SHORT)
                        .show();

                    insertmail();

                    myDialog.dismiss();
                  }
                });

            myDialog.show();
          }
        });

    inbox.setOnClickListener(
        new TextView.OnClickListener() {
          public void onClick(View v) {
            tbl3.setVisibility(View.GONE);
            tbl2.removeAllViews();
            getinbox();
            tbl2.setVisibility(View.VISIBLE);
          }
        });
    sent.setOnClickListener(
        new TextView.OnClickListener() {
          public void onClick(View v) {
            tbl2.setVisibility(View.GONE);

            tbl3.removeAllViews();

            getsent();
            tbl3.setVisibility(View.VISIBLE);
          }
        });
    data.deletemailboxfrom();
    call();
  }