2012-05-09 9 views
0

私はMainClassを持っています。これは完全なアプリケーションです。ボタンをクリックすると、ポップアップのように見える別のクラス(PopupValores)に行きます。このクラスでは、整数を入力するEditTextと、このクラスを閉じるボタンがあります。私の質問は、そのintをPopupClassに入力してMainClassで使用する方法です。 PopupValoresのコードを引用します。クラスを終了し、クラスを終了してメインクラスにintを取得

import android.app.Activity; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.TextView; 

public class PopupValores extends Activity implements OnClickListener { 

TextView texto; 
String mensaje; 
EditText editable; 
Button ok; 
public static int cantidad; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.popupvalores); 

    ok = (Button) findViewById (R.id.Bok); 
    texto = (TextView) findViewById (R.id.textView1); 
    editable = (EditText) findViewById (R.id.editText1); 
    mensaje = editable.getText().toString(); 
    ok.setOnClickListener(this); 

    ok.setOnLongClickListener(new View.OnLongClickListener() { 
     public boolean onLongClick(View arg0) { 
      finish(); 
      return true; 
     } 
    }); 


} 

public void onClick(View v){ 
    switch(v.getId()){ 
    case R.id.Bok: 

    String mensaje; 
    mensaje = editable.getText().toString(); 

    cantidad = Integer.parseInt(mensaje); 

    texto.setText("New value " + cantidad + "."); 

    } 
} 
} 

その後、私MainClassに私はボタンをクリックして、それがint型

int id, vaas = PopupValores.cantidad; 
public void onClick (View v) 
{ 
posicion = (ImageCell) v; 
seleccion = posicion.mCellNumber; 

if (seleccion == -1){ 
    .... 
    toast (id + " " + vaas); 
    .... 
} 
} 

を示ししかし、その代わりにPopupValoresで宣言された値を示したのは、私がここで間違ってやっている何0を示して?

答えて

1
  1. があるstartActivityforResult と呼ばれ、stackoverflowの上、ここで洙何回も回答されていますActivity.setResult()(インテントのバンドルにデータを保存できます)
  2. メインアクティビティでonActivityResultを上書きし、データを取得します。
0

そのここであなたが経由で要求された結果を設定し、一度ポップアップ活動を終えActivity.startActivityForResult()

  • でポップアップアクティビティを呼び出す必要がone

  • 関連する問題