1

嗨,我有两个活动,第一个活动有三个图标,一个是不可见的......当我点击第一个活动时,它使用意图进入第二个活动..我的第二个活动是登录屏幕,当登录成功时我应该来返回第一个活动并使图标在第一个活动中可见..我如何从第二个活动返回到第一个活动并使图标在第一个活动中可见..以下是我的登录屏幕代码

public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            setContentView(R.layout.fyelogin);                    
            etPassword = (EditText)findViewById(R.id.password);
            btnLogin = (Button)findViewById(R.id.login_button);
            btnCancel = (Button)findViewById(R.id.cancel_button);
            lblResult = (TextView)findViewById(R.id.result);

            final ImageView details = (ImageView)findViewById(R.id.red); 

            btnLogin.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {

                    String password = etPassword.getText().toString();

                    if(password.equals("guest")){
                        lblResult.setText("password successful.");

              // details.setVisibility(View.VISIBLE);


                    } else {
                        lblResult.setText("password doesn't match.");

                    }                                      
                    finish();}});

任何建议/帮助表示赞赏...

4

1 回答 1

2

用于startActivityforResult打开登录活动..然后onActivityResult(int, int, Intent)在您的第一个活动中显示图标..

例子:

public class MyActivity extends Activity {
 ...

 static final int PICK_CONTACT_REQUEST = 0;

 protected boolean onKeyDown(int keyCode, KeyEvent event) {
     if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
         // When the user center presses, let them pick a contact.
         startActivityForResult(
             new Intent(Intent.ACTION_PICK,
             new Uri("content://contacts")),
             PICK_CONTACT_REQUEST);
        return true;
     }
     return false;
 }

 protected void onActivityResult(int requestCode, int resultCode,
         Intent data) {
     if (requestCode == PICK_CONTACT_REQUEST) {
         if (resultCode == RESULT_OK) {
             // A contact was picked.  Here we will just display it
             // to the user.
             startActivity(new Intent(Intent.ACTION_VIEW, data));
         }
     }
 }
}

检查http://developer.android.com/reference/android/app/Activity.html

于 2012-11-29T08:51:38.567 回答