将字符串从ClassA移动到Android上的Calendar中的B类

时间:2012-04-29 02:27:57

标签: java android

我尝试了几种方法,但是没有方法可以解决我的代码问题。无论如何,这是我在classA上的onclick代码。

public void onClick(View view)
{
    String date_month_year = (String) view.getTag();
    selectedDayMonthYearButton.setText("Selected: " + date_month_year);

    try
    {
        // comment added by SO: enter code here
        Date parsedDate = dateFormatter.parse(date_month_year);
        Log.d(tag, "Parsed Date: " + parsedDate.toString());
    }
    catch (ParseException e)
    {
        e.printStackTrace();
    }

    switch(view.getId())
    {
        case R.id.button1:
            Intent i = new Intent(DatabaseSample.this, SaveData.class);  
            startActivity(i);
            break;

    }
}

    public int getCurrentDayOfMonth()
    {
        return currentDayOfMonth;
    }

    private void setCurrentDayOfMonth(int currentDayOfMonth)
    {
            this.currentDayOfMonth = currentDayOfMonth;
    }
    public void setCurrentWeekDay(int currentWeekDay)
    {
            this.currentWeekDay = currentWeekDay;
    }
    public int getCurrentWeekDay()
    {
            return currentWeekDay;
    }
}
}

我想将字符串 date_month_year 移动到另一个类并显示它。这是我的B类代码。我想知道字符串的读取位置以及如何从A类到B类。 当用户点击其中一个日期时,字符串date_month_year将是年份和月份的日期,即12/12/2012我想复制该字符串并在CLASS B中显示 *

package com.app.DatabaseSample;

import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;

public class SaveData extends Activity implements OnClickListener {  
    private DataManipulator dh;     
    static final int DIALOG_ID = 0;

    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.save);
        View add = findViewById(R.id.Button01add);
        add.setOnClickListener(this);
        View home = findViewById(R.id.Button01home);
        home.setOnClickListener(this);           
    }

    public void onClick(View v){
        switch(v.getId()){

        case R.id.Button01home:
            Intent i = new Intent(this, DatabaseSample.class);
            startActivity(i);
            break;

        case R.id.Button01add:
            View editText1 = (EditText) findViewById(R.id.name);
            View editText2 = (EditText) findViewById(R.id.number);
            View editText3 = (EditText) findViewById(R.id.skypeId);
            View editText4 = (EditText) findViewById(R.id.address); 
            String myEditText1=((TextView) editText1).getText().toString();
            String myEditText2=((TextView) editText2).getText().toString();
            String myEditText3=((TextView) editText3).getText().toString();
            String myEditText4=((TextView) editText4).getText().toString();

            this.dh = new DataManipulator(this);
            this.dh.insert(myEditText1,myEditText2,myEditText3,myEditText4);

            showDialog(DIALOG_ID);
            break;

        }
    }  
    protected final Dialog onCreateDialog(final int id) {
        Dialog dialog = null;
        switch(id) {
        case DIALOG_ID:
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage("Information saved successfully ! Add Another Info?")
            .setCancelable(false)
            .setPositiveButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    SaveData.this.finish();

              }
            })
            .setNegativeButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
            AlertDialog alert = builder.create(); 
            dialog = alert;
            break;

        default:

        }
        return dialog;
    }



}

0 个答案:

没有答案