第六天 | |
所花时间(包括上课) | 3h |
代码量(行) | 100行 |
博客量(篇) | 1篇 |
所学习到的内容 | android 的页面制作(下拉框,如何输入文字等) |
package com.example.myapplication1; import androidx.appcompat.app.AppCompatActivity; import android.annotation.SuppressLint; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.util.Log; import android.view.View; import android.widget.EditText; import android.widget.Toast; import android.widget.ArrayAdapter; import android.widget.Spinner; import com.example.myapplication1.dao.UserDao; import com.example.myapplication1.entity.User; /** * function:连接注册页面 */ public class activity_register extends AppCompatActivity { private static final String TAG = "mysql-application1-register"; EditText userAccount = null; EditText userName = null; Spinner userPassword; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_register); userAccount = findViewById(R.id.userAccount); userPassword = findViewById(R.id.userPassword); userName = findViewById(R.id.userName); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.location_options, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); userPassword.setAdapter(adapter); } public void register(View view){ String userAccount1 = userAccount.getText().toString(); String userPassword1 = userPassword.getSelectedItem().toString(); String userName1 = userName.getText().toString(); User user = new User(); user.setUserAccount(userAccount1); user.setUserPassword(userPassword1); user.setUserName(userName1); user.setUserType(1); user.setUserState(0); user.setUserDel(0); if(userName1.equals("王建民") || userName1.equals("刘立嘉")||userName1.equals("刘丹")||userName1.equals("杨子光")||userName1.equals("张云霞")||userName1.equals("武永亮")||userName1.equals("高飞")||userName1.equals("孙静")||userName1.equals("黄荣峰")) { new Thread(){ @Override public void run() { int msg = 0; UserDao userDao = new UserDao(); User uu = userDao.findUser(user.getUserAccount()); if(uu != null){ msg = 1; } else{ boolean flag = userDao.register(user); if(flag){ msg = 2; } } hand.sendEmptyMessage(msg); } }.start();} else { // 如果用户名不是特定值,给出提示 Toast.makeText(getApplicationContext(), "只允许指定老师创建注册", Toast.LENGTH_SHORT).show(); } } @SuppressLint("HandlerLeak") final Handler hand = new Handler() { public void handleMessage(Message msg) { if(msg.what == 0) { Toast.makeText(getApplicationContext(),"注册失败失败",Toast.LENGTH_LONG).show(); } else if(msg.what == 1) { Toast.makeText(getApplicationContext(),"该课程已经存在,请换一个账号",Toast.LENGTH_LONG).show(); } else if(msg.what == 2) { Toast.makeText(getApplicationContext(), "注册成功", Toast.LENGTH_LONG).show(); Intent intent = new Intent(); //将想要传递的数据用putExtra封装在intent中 intent.putExtra("a","注册"); setResult(RESULT_CANCELED,intent); finish(); } } }; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。