gpt4 book ai didi

java - 如果显示对话框,当用户按下后退按钮时调用哪个方法?

转载 作者:行者123 更新时间:2023-11-30 11:58:15 25 4
gpt4 key购买 nike

我按以下方式定义了一个对话框:

public void displayAvailableDevices(Vector<UserDevice> availableDevices) {

connector.setDevicesFound(true);
UserDevice[] devices = new UserDevice[availableDevices.size()];

for (int i = 0; i < availableDevices.size(); i++) {
devices[i] = availableDevices.elementAt(i);
}

Arrays.sort(devices);

Vector<UserDevice> sorted = new Vector<UserDevice>();
for (int j = 0; j < devices.length; j++) {
sorted.add(devices[j]);
}

allAvailableDevices = sorted;

connector.stopNeighbourDiscovery();
if (dialog != null) {
dialog.dismiss();
checkedUser = null;
}
dialog = new Dialog(this);
dialog.setContentView(R.layout.available_users);
dialog.setTitle("Available Devices");

RelativeLayout rootLayer = (RelativeLayout) dialog.findViewById(R.id.dialogRoot);
rootLayer.setBackgroundColor(Color.WHITE);

ListView userTable = (ListView) dialog.findViewById(R.id.userList);
adapter = new UserAdapter();
userTable.setAdapter(adapter);
userTable.setOnItemClickListener(new UserListener());

DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);

connect = (Button) dialog.findViewById(R.id.userList_connect);
connect.setMinWidth(dm.widthPixels / 2);
connect.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
if (checkedUser != null) {
dialog.dismiss();
connector.connectToDevice(checkedUser);
}
}

});

Button start = (Button) dialog.findViewById(R.id.userList_start);
start.setMinWidth(dm.widthPixels / 2);
start.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
dialog.dismiss();
startProfileView();
}

});

Button refresh = (Button) dialog.findViewById(R.id.userList_refresh);
refresh.setMinWidth(dm.widthPixels / 2);
refresh.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
dialog.dismiss();
getGameBaseLayer().resetAvailableUserDevices();
connector.refresh();
}

});

Button cancel = (Button) dialog.findViewById(R.id.userList_cancel);
cancel.setMinWidth(dm.widthPixels / 2);
cancel.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
finish();
}

});

dialog.show();
if (checkedUser == null) {
connect.setEnabled(false);
}

}

如果显示此对话框并且用户按下后退按钮,则关闭该对话框。但是我想做一些进一步的处理,但是我如何检测用户是否按下了后退按钮?

最佳答案

我很肯定 this article可以帮助很多。据我了解,按“返回”就像取消对话框(如按“取消”)。它们展示了如何使对话不可取消以及如何实现监听器以捕获“取消”事件。

关于java - 如果显示对话框,当用户按下后退按钮时调用哪个方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3277124/

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