我在一个片段中设置了一个监听器,用于各种按钮,其中一个应该是注销,将用户返回到MainActivity。出于某种原因,它似乎没有做任何onClick;没有错误,没有活动启动。我的代码没有看到任何明显的错误,是否有人可以提出有关为什么它似乎无效的建议?
这是switch语句中的最后一种情况。
//this handles our button click event
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnHelp1:
// Help message for title
//First we instantiate the dialog
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
//then set the strings for dialogtitle and message
builder.setMessage(R.string.dialog_help1)
.setTitle(R.string.dialog_title_help1);
//set the OK button
builder.setPositiveButton(R.string.dialog_btn_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User clicked OK button, dismiss dialog
dialog.dismiss();
}
});
//then we pop it on screen
AlertDialog dialog = builder.create();
dialog.show();
break;
case R.id.btnHelp2:
// Help message for name
AlertDialog.Builder builder2 = new AlertDialog.Builder(getActivity());
builder2.setMessage(R.string.dialog_help2)
.setTitle(R.string.dialog_title_help2);
builder2.setPositiveButton(R.string.dialog_btn_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User clicked OK button, dismiss dialog
dialog.dismiss();
}
});
AlertDialog dialog2 = builder2.create();
dialog2.show();
break;
case R.id.btnHelp3:
// Help message for surname
AlertDialog.Builder builder3 = new AlertDialog.Builder(getActivity());
builder3.setMessage(R.string.dialog_help3)
.setTitle(R.string.dialog_title_help3);
builder3.setPositiveButton(R.string.dialog_btn_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User clicked OK button, dismiss dialog
dialog.dismiss();
}
});
AlertDialog dialog3 = builder3.create();
dialog3.show();
break;
case R.id.btnHelp4:
// Help message for other name
AlertDialog.Builder builder4 = new AlertDialog.Builder(getActivity());
builder4.setMessage(R.string.dialog_help4)
.setTitle(R.string.dialog_title_help4);
builder4.setPositiveButton(R.string.dialog_btn_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User clicked OK button, dismiss dialog
dialog.dismiss();
}
});
AlertDialog dialog4 = builder4.create();
dialog4.show();
break;
case R.id.btnHelp5:
// Help message for name
AlertDialog.Builder builder5 = new AlertDialog.Builder(getActivity());
builder5.setMessage(R.string.dialog_help5)
.setTitle(R.string.dialog_title_help5);
builder5.setPositiveButton(R.string.dialog_btn_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User clicked OK button, dismiss dialog
dialog.dismiss();
}
});
AlertDialog dialog5 = builder5.create();
dialog5.show();
break;
case R.id.btnSave1:
// Save button onClick()
//set input strings
String title = inputTitle.getText().toString();
String surname = inputSurname.getText().toString();
String name = inputName.getText().toString();
String other = inputOther.getText().toString();
String mother = inputMother.getText().toString();
//check they have been completed
if (!title.isEmpty() &&
!surname.isEmpty() &&
!name.isEmpty() &&
!other.isEmpty() &&
!mother.isEmpty()) {
updateUserA(email, title, surname, name, other, mother);
} else {
Toast.makeText(getActivity(),
"Please enter your details!", Toast.LENGTH_LONG)
.show();
}
break;
case R.id.btnLog1:
// logout user
session.setLogin(false);
db.deleteUsers();
// Launching the main activity
Intent intent = new Intent(getActivity(), MainActivity.class);
startActivity(intent);
break;
default:
break;
}
}
答案 0 :(得分:0)
使用此功能。
didReceiveLocalNotification
如果没有点击,也尝试调试,如果没有,我的猜测是ID错误或你忘了设置监听器或将其分配给错误的视图。
答案 1 :(得分:0)
检查片段的layout.xml。最有可能它有错误的背景。
答案 2 :(得分:0)
我是个白痴,我从未在onCreateView上添加按钮...对不起家伙,漫长的一天