0

我遇到了无法从活动中回调的问题。将表单 Activity 1 输入到 Activity 2 但它无法返回。谁能告诉我我哪里做错了?
这是我的代码:

活动一:

OnClickListener changeTextOnClickListener = new OnClickListener() {

  @Override
  public void onClick(View v) {
    Intent intent = new Intent(getApplicationContext(), Setting.class);

    startActivityForResult(intent, CHANGETEXT);

  }

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  // TODO Auto-generated method stub
  super.onActivityResult(requestCode, resultCode, data);

  if (resultCode == RESULT_OK) {
    switch (requestCode) {
      case CHANGETEXT:
      Bundle b = data.getExtras();
      this.Text = b.getString("Text");

    }
  }
}  

活动二:

@Override
public void onClick(View v) {
  // TODO Auto-generated method stub
  Bundle b = new Bundle();
  Intent intent = new Intent();
  newText.setText(newText.getText().toString());
  Toast.makeText(getApplicationContext(),
    newText.getText().toString(), Toast.LENGTH_LONG).show();
  b.putString("Text", newText.getText().toString());
  intent.putExtras(b);
  setResult(RESULT_OK, intent);
  finish();

}

显现:

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.shotboxv3.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name="com.example.shotboxv3.Setting"
        android:label="@string/app_name" >

    </activity>
</application>
4

1 回答 1

0

由于是Activity实现了OnClickListener,所以在Activity 2的onCreate中,你需要将你点击的按钮的监听器设置为它所在的Activity:

myButton.setOnClickListener(this);
于 2013-07-09T21:11:53.600 回答