gpt4 book ai didi

java - 在 Activity 创建失败时显示弹出窗口

转载 作者:行者123 更新时间:2023-12-02 13:42:47 25 4
gpt4 key购买 nike

我试图在 create() 方法上的 Activity 上显示 popup 但似乎没有发生任何事情..没有 异常(exception) 没有 弹出窗口

以下是代码

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
btnClear = (Button)findViewById(R.id.btnClear);
txtPassword = (TextView) findViewById(R.id.txtPassword);
txtPassword.setOnTouchListener(otl);
btnClear.setVisibility(View.GONE);
objDBHelper = DBHelper.getInstance(getApplicationContext());
SQLiteDatabase db = objDBHelper.getWritableDatabase();
long driverProfileCount = objDBHelper.getProfilesCount(db);

initiatePasswordPopupWindow(); // show pop up when no data is in table

}

private void initiatePasswordPopupWindow() {
try {
//We need to get the instance of the LayoutInflater, use the context of this activity
LayoutInflater inflater = (LayoutInflater) Login.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//Inflate the view from a predefined XML layout
final View layout = inflater.inflate(R.layout.setting_password_popup,
(ViewGroup) findViewById(R.id.setting_password_popup_element));
// create a 300px width and 470px height PopupWindow
pw = new PopupWindow(layout, 600, 720, true);
// display the popup in the center
layout.post(new Runnable() {
public void run() {
pw.showAtLocation(layout, Gravity.CENTER, 0, 0);
Button cancelButton = (Button) layout.findViewById(R.id.end_data_send_button);
cancelButton.setOnClickListener(cancel_button_click_listener);
}
});

/* TextView mResultText = (TextView) layout.findViewById(R.id.server_status_text);*/


} catch (Exception e) {
e.printStackTrace();
}
}

我缺少什么?

最佳答案

您尝试将 post 与 View (PopupWindow 布局)一起使用,但该 View 不会启动其消息队列。尝试使用已处于 Activity 状态的 View ,例如 Root View - 将 layout.post(new Runnable() {) 更改为 findViewById(android.R.id.content):

findViewById(android.R.id.content).post(new Runnable() {
public void run() {
pw.showAtLocation(layout, Gravity.CENTER, 0, 0);

Button cancelButton = (Button) layout.findViewById(R.id.end_data_send_button);
cancelButton.setOnClickListener(cancel_button_click_listener);
}
});

关于java - 在 Activity 创建失败时显示弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42644714/

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