android编辑对话框,android – 如何在一个对话框中编辑文本框

我想在一个对话框中输入一个编辑文本框输入密码。

当我在做我不能做。我是一个初学者。

请帮助我在这。

public class MainActivity extends Activity {

Button create, show, setting;

//String pass="admin";String password;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

create = (Button)findViewById(R.id.amcreate);

setting = (Button)findViewById(R.id.amsetting);

show = (Button)findViewById(R.id.amshow);

//input = (EditText)findViewById(R.id.this);

setting.setVisibility(View.INVISIBLE);

create.setOnClickListener(new View.OnClickListener() {

public void onClick(View view) {

Intent myIntent1 = new Intent(view.getContext(), Create.class);

startActivityForResult(myIntent1, 0);

}

});

show.setOnClickListener(new View.OnClickListener() {

//@SuppressWarnings("deprecation")

public void onClick(final View view) {

// Creating alert Dialog with one Button

AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);

//AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();

// Setting Dialog Title

alertDialog.setTitle("PASSWORD");

// Setting Dialog Message

alertDialog.setMessage("Enter Password");

**final EditText input = new EditText(this);**

//alertDialog.setView(input);

// Setting Icon to Dialog

alertDialog.setIcon(R.drawable.key);

// Setting Positive "Yes" Button

alertDialog.setPositiveButton("YES",

new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog,int which) {

// Write your code here to execute after dialog

Toast.makeText(getApplicationContext(),"Password Matched", Toast.LENGTH_SHORT).show();

Intent myIntent1 = new Intent(view.getContext(), Show.class);

startActivityForResult(myIntent1, 0);

}

});

// Setting Negative "NO" Button

alertDialog.setNegativeButton("NO",

new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {

// Write your code here to execute after dialog

dialog.cancel();

}

});

// closed

// Showing Alert Message

alertDialog.show();

}

});

图片

我想得到

AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);

alertDialog.setTitle("PASSWORD");

alertDialog.setMessage("Enter Password");

final EditText input = new EditText(MainActivity.this);

LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(

LinearLayout.LayoutParams.MATCH_PARENT,

LinearLayout.LayoutParams.MATCH_PARENT);

input.setLayoutParams(lp);

alertDialog.setView(input);

alertDialog.setIcon(R.drawable.key);

alertDialog.setPositiveButton("YES",

new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {

password = input.getText().toString();

if (password.compareTo("") == 0) {

if (pass.equals(password)) {

Toast.makeText(getApplicationContext(),

"Password Matched", Toast.LENGTH_SHORT).show();

Intent myIntent1 = new Intent(view.getContext(),

Show.class);

startActivityForResult(myIntent1, 0);

} else {

Toast.makeText(getApplicationContext(),

"Wrong Password!", Toast.LENGTH_SHORT).show();

}

}

}

});

alertDialog.setNegativeButton("NO",

new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {

dialog.cancel();

}

});

alertDialog.show();

}

});

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值