gpt4 book ai didi

Android:显示另一个 Activity 的 Activity View

转载 作者:行者123 更新时间:2023-11-29 21:54:23 25 4
gpt4 key购买 nike

嗨,我有两个 Activity ,第一个 Activity 有三个图标,一个是不可见的...当我点击第一个 Activity 时,它会使用 Intent 转到第二个 Activity ..我的第二个 Activity 是登录屏幕,当登录成功时我应该回到第一个 Activity 并在第一个 Activity 中显示一个图标..我怎样才能从第二个 Activity 返回到第一个 Activity 并使图标在第一个 Activity 中可见..下面是我的登录屏幕代码

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();}});

感谢任何建议/帮助...

最佳答案

使用 startActivityforResult 打开登录 Activity ..然后在第一个 Activity 的 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

关于Android:显示另一个 Activity 的 Activity View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13621914/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com