4 回答
TA贡献1827条经验 获得超4个赞
你为什么使用这样的点击监听器:findViewById(R.id.btnSave).setOnClickListener(null);
改为这样做:
findViewById(R.id.btnSave).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//put all your textView logic here
}
});
TA贡献1155条经验 获得超0个赞
更改此行:
findViewById(R.id.btnSave).setOnClickListener(null);
进入
findViewById(R.id.btnSave).setOnClickListener(btnSaveListener);
onCreate并从方法中删除以下行。
然后创建btnSaveListener如下:
private View.OnClickListener btnSaveListener =new View.OnClickListener() {
@Override
public void onClick(View v) {
// here goes all the code belove the line you change in the method `onCreate`
}
};
TA贡献1850条经验 获得超11个赞
最后,这不是我如何设置听众的问题。
将活动调用从我的MainActivity启动类更改为StartActivity意味着OnCreate代码被正确调用。
TA贡献1853条经验 获得超18个赞
你的按钮点击监听器实现是错误的,试试这样:
findViewById(R.id.action_ask).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Check that all text boxes have a value in them
if (txtServer.getText().length() == 0)
{
// MESSAGE BOX
AlertDialog.Builder msg = new AlertDialog.Builder(this);
msg.setTitle("Enter Server");
msg.setMessage("Please enter a server address.");
msg.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Leave this blank, this will mean nothing happens, the msg just disappears
}
});
}
if (txtFolder.getText().length() == 0)
{
// MESSAGE BOX
AlertDialog.Builder msg = new AlertDialog.Builder(this);
msg.setTitle("Enter Folder");
msg.setMessage("Please enter a folder to use.");
msg.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Leave this blank, this will mean nothing happens, the msg just disappears
}
});
}
if (txtUsername.getText().length() == 0)
{
// MESSAGE BOX
AlertDialog.Builder msg = new AlertDialog.Builder(this);
msg.setTitle("Enter Username");
msg.setMessage("Please enter your username.");
msg.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Leave this blank, this will mean nothing happens, the msg just disappears
}
});
}
if (txtPassword.getText().length() == 0)
{
// MESSAGE BOX
AlertDialog.Builder msg = new AlertDialog.Builder(this);
msg.setTitle("Enter Server");
msg.setMessage("Please enter a your password.");
msg.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Leave this blank, this will mean nothing happens, the msg just disappears
}
});
}
}
});
添加回答
举报
