android doinbackground toast,android ProgressDialog Toast

这个博客展示了如何在Android应用程序中实现PIN码验证。它创建了一个`InputPINActivity`类,该类包含一个`TextView`和一个`Button`。当用户点击按钮时,会触发一个异步任务`SendAsynTask`,该任务负责获取输入的PIN码并进行验证。如果PIN码正确,`TextView`显示'Right!',否则显示错误提示。
摘要由CSDN通过智能技术生成

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

public class InputPINActivity extends Activity{

TextView tv;

Toast toast;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.pin_passwd);

sure_btn = (Button) findViewById(R.id.sure_btn);

sure_btn.setOnClickListener(pwd_sub);

}

/*realize Asyn loading*/

private class SendAsynTask extends AsyncTask {

private Activity activity;

private ProgressDialog progressDialog;

public SendAsynTask(Activity activity) {

this.activity = activity;

progressDialog = new ProgressDialog(activity);

}

protected void onPreExecute() {

this.progressDialog.setMessage("Loading...");

this.progressDialog.show();

}

@Override

protected void onPostExecute(final Boolean success) {

if (progressDialog.isShowing()) {

progressDialog.dismiss();

}

}

@Override

protected Boolean doInBackground(String... params) {

showInfo(params[0]);

return true;

}

}

/* the sure Button click event */

private OnClickListener pwd_sub = new OnClickListener() {

@Override

public void onClick(View v) {

pinPwd = pinText.getText().toString().trim(); // get the text from EditView

SendAsynTask task=new SendAsynTask(InputActivity.this);

task.execute(new String[] { pwd });

}

private void showInfo(String pwd) {

if(!pwd.equals("")) {

tv.setText("Right!");

} else {

toast = Toast.makeText(getApplicationContext(), "Wrong!",

Toast.LENGTH_SHORT);

toast.setGravity(Gravity.CENTER, 0, 0);

toast.show();

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值