我有两个类NoteEdit和NoteView,在NoteView类中,我按编辑按钮将其定向到NoteEidt类,假设我想将更新后的主体信息传递给NoteView,并且以前的主体信息应该已经在NoteView界面中进行了更新,但是仍然保持不变,这是我的代码的一部分,请帮助,谢谢!

NoteEdit类:

     Intent resultIntent = new Intent(NoteEdit.this, NoteView.class);
           String body = mBodyText.getText().toString()
         resultIntent.putExtra(body, true);


NoteView类

      public boolean onOptionsItemSelected(MenuItem item) {

          switch (item.getItemId()) {
    case DIARY_EDIT:
         Intent i = new Intent(NoteView.this, NoteEdit.class);
         i.putExtra(NotesDbAdapter.KEY_ROWID, mRowId);
         startActivityForResult(i, ACTIVITY_VIEWERS);
         break;
          }  }

         @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
        switch(requestCode) {
        case (ACTIVITY_VIEWERS)
        : {
            if (resultCode == Activity.RESULT_OK)
            {
                Bundle extras = getIntent().getExtras();
                 newText =extras.getString(NotesDbAdapter.KEY_BODY);
                // TODO Update your TextView.
                }
            break;
            }
        }


    }

最佳答案

现在使用此代码。

NoteEdit类:

Intent resultIntent = new Intent(NoteEdit.this, NoteView.class);
       String body = mBodyText.getText().toString()
     resultIntent.putExtra(NotesDbAdapter.KEY_BODY, body);
     setResult(RESULT_OK,resultIntent);


NoteView类:

public boolean onOptionsItemSelected(MenuItem item) {

      switch (item.getItemId()) {
case DIARY_EDIT:
     Intent i = new Intent(NoteView.this, NoteEdit.class);
     i.putExtra(NotesDbAdapter.KEY_ROWID, mRowId);
     startActivityForResult(i, ACTIVITY_VIEWERS);
     break;
      }  }

     @Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    switch(requestCode) {
    case ACTIVITY_VIEWERS
    : {
        if (resultCode == RESULT_OK)
        {
            Bundle extras = intent().getExtras();
             newText =extras.getString(NotesDbAdapter.KEY_BODY);
            // TODO Update your TextView.
            }
        break;
        }
    }


}

关于android - 返回结果时将结果表单当前 Activity 传递给第一个 Activity ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7144002/

10-09 13:25