tags:

views:

43

answers:

2

please give me the solution

public class Calc extends Activity implements OnClickListener 
{
       private Button clr;            
       clr=(Button)findViewById(R.id.Button01);
}

public void onClick(View v)
{
   case R.id.Button01:       
       tv1.setText("REF");
       if( ref_flg==true)
       {
          final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
          alertDialog.setTitle("Reset...");
          alertDialog.setMessage("REF was already entered");
          alertDialog.setButton2("OK", new DialogInterface.OnClickListener()
          {
              public void onClick(DialogInterface dialog, int which) {
                  // here you can add functions
                  dialog.dismiss();
              }
          });
          alertDialog.setIcon(R.drawable.icon);
          alertDialog.show();
       } 
}

so my question is that how i can write the code in case button01 in another activity and get the result from it.

A: 

To communicate between two activities: http://developer.android.com/reference/android/app/Activity.html#StartingActivities

WarrenFaith
+2  A: 

startActivityForResult example:

Intent intent = new Intent(this, com.example.app.YOURCLASS);
startActivityForResult(intent);

Listening for results:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // See which child activity is calling us back.
    switch (resultCode) {
        case MY_RESULT_CODE:
            // Do something
        default:
            break;
    }
}

Sending results from other activity:

private OnClickListener myListener = new OnClickListener() {
    public void onClick(View v) {
        Bundle data= new Bundle();
        data.putString("data",""); 
        setResult(RESULT_OK, "DataName", data);
        finish();
    }
}
BeRecursive