4 回答

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超4個(gè)贊
你為什么使用這樣的點(diǎn)擊監(jiān)聽器: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貢獻(xiàn)1155條經(jīng)驗(yàn) 獲得超0個(gè)贊
更改此行:
findViewById(R.id.btnSave).setOnClickListener(null);
進(jìn)入
findViewById(R.id.btnSave).setOnClickListener(btnSaveListener);
onCreate并從方法中刪除以下行。
然后創(chuàng)建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貢獻(xiàn)1850條經(jīng)驗(yàn) 獲得超11個(gè)贊
最后,這不是我如何設(shè)置聽眾的問(wèn)題。
將活動(dòng)調(diào)用從我的MainActivity
啟動(dòng)類更改為StartActivity
意味著OnCreate
代碼被正確調(diào)用。

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超18個(gè)贊
你的按鈕點(diǎn)擊監(jiān)聽器實(shí)現(xiàn)是錯(cuò)誤的,試試這樣:
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
}
});
}
}
});
添加回答
舉報(bào)