teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

余計なko-dowosakuzixyo

2017/06/09 23:16

投稿

edoooooo
edoooooo

スコア478

title CHANGED
File without changes
body CHANGED
@@ -11,52 +11,46 @@
11
11
  ```
12
12
 
13
13
  ```java
14
- public String newSet(LayoutInflater inflaters, final Context contexts,View layouts,InputMethodManager inputMethodManagers) {
14
+ public String newSet(LayoutInflater inflaters, final Context contexts,View layouts,InputMethodManager inputMethodManagers) {
15
15
 
16
-
16
+
17
17
  builder = new AlertDialog.Builder(context);
18
18
  builder.setView(layout);
19
19
  builder.setNegativeButton("ログイン", new DialogInterface.OnClickListener() {
20
- public void onClick(DialogInterface dialog, int which) {
20
+ public void onClick(DialogInterface dialog, int which) {
21
- EditText getusername2 = (EditText) layout.findViewById(R.id.username);
21
+ EditText getusername2 = (EditText) layout.findViewById(R.id.username);
22
- EditText getpassword2 = (EditText) layout.findViewById(R.id.password);
23
- String getusername = getusername2.getText().toString();
22
+ String getusername = getusername2.getText().toString();
24
- String password = getpassword2.getText().toString();
23
+
25
- //データベースから取得してあればログイン
24
+ //データベースから取得してあればログイン
26
- String sql = "select username from user where username = '" + getusername + "' and password = '" + password + "';";
25
+ String sql = "select username from user where username = '" + getusername + "';";
27
- System.out.println(sql);/////////////////////ログ出力
26
+ System.out.println(sql);/////////////////////ログ出力
28
- MyOpenHelper helper = new MyOpenHelper(context);
27
+ MyOpenHelper helper = new MyOpenHelper(context);
29
- SQLiteDatabase db = helper.getWritableDatabase();
28
+ SQLiteDatabase db = helper.getWritableDatabase();
30
- Cursor c = db.rawQuery(sql, null);
29
+ Cursor c = db.rawQuery(sql, null);
31
- Integer count = c.getCount();
30
+ Integer count = c.getCount();
32
- if (count != 0) {
31
+ if (count != 0) {
33
- c.moveToFirst();
32
+ c.moveToFirst();
34
- String checkusername = c.getString(0);
33
+ String checkusername = c.getString(0);
35
- //ログインする
36
- Toast toast = Toast.makeText(context, "ログインしました", Toast.LENGTH_SHORT);
34
+ Toast toast = Toast.makeText(context, "ログインしました", Toast.LENGTH_SHORT);
37
- toast.show();
35
+ toast.show();
38
- //そして、usernameにset
39
- System.out.println("checkusername:"+checkusername);/////////////////////ログ出力
36
+ System.out.println("checkusername:"+checkusername);/////////////////////ログ出力
40
- username = checkusername;
37
+ username = checkusername;
41
- System.out.println("username:"+username);/////////////////////ログ出力
38
+ System.out.println("username:"+username);/////////////////////ログ出力
42
- System.out.println("ログイン完了" + username);/////////////////////ログ出力
39
+ System.out.println("ログイン完了" + username);/////////////////////ログ出力
43
-
40
+ }
44
41
 
45
- }
46
-
47
- });
42
+ });
48
- alertDialog = builder.create();
43
+ alertDialog = builder.create();
49
44
  alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
50
45
 
46
+ @Override
47
+ public void onShow(DialogInterface arg0) {
48
+ getusername2 = (EditText) layout.findViewById(R.id.username);
49
+ //inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
50
+ inputMethodManager.showSoftInput(getusername2, 0);
51
+ }
51
52
 
52
- @Override
53
- public void onShow(DialogInterface arg0) {
54
- getusername2 = (EditText) layout.findViewById(R.id.username);
55
- //inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
56
- inputMethodManager.showSoftInput(getusername2, 0);
57
- }
58
-
59
- });
53
+ });
60
54
  alertDialog.show();
61
55
 
62
56
  System.out.println("return usernmae;:"+username);/////////////////////ログ出力