質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.51%
Server+

Server+は、IT業界団体CompTIAが認定しているサーバー業務に関する資格です。サーバーのHW/SW構築・メンテナンス・仮想化など、サーバー運営上の運用・管理において幅広く対応できるスキルを評価します。

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Q&A

解決済

1回答

2079閲覧

Androidアプリでログインする時にPasswordとUserIdをサーバーにputしたいのですがどうすればいいのでしょうか?

edoooooo

総合スコア476

Server+

Server+は、IT業界団体CompTIAが認定しているサーバー業務に関する資格です。サーバーのHW/SW構築・メンテナンス・仮想化など、サーバー運営上の運用・管理において幅広く対応できるスキルを評価します。

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

0グッド

0クリップ

投稿2016/10/31 06:12

編集2016/10/31 08:05

java

1 obj2.put("Password", Password); 2 obj2.put("UserName",UserName);

このようなコードではcan not resolve symbol Password,UserNameとなります。

どうすれば、この下の、xmlのPasswordとUserNameをputできるのでしょうか?

xml

1<?xml version="1.0" encoding="utf-8"?> 2<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:tools="http://schemas.android.com/tools" 4 xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" 5 android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 6 android:paddingRight="@dimen/activity_horizontal_margin" 7 android:paddingTop="@dimen/activity_vertical_margin" 8 android:paddingBottom="@dimen/activity_vertical_margin" 9 app:layout_behavior="@string/appbar_scrolling_view_behavior" 10 tools:showIn="@layout/activity_activity_second" 11 tools:context="ncmbdataquick.mbaas.com.nifty.datastorequickstart.ActivitySecond"> 12 13 <Button 14 android:layout_width="wrap_content" 15 android:layout_height="wrap_content" 16 android:text="登録する" 17 android:onClick="NewUserSet" 18 android:id="@+id/NewUserSet" 19 android:layout_centerVertical="true" 20 android:layout_alignLeft="@+id/ToLogin" 21 android:layout_alignStart="@+id/ToLogin" /> 22 23 <Button 24 android:layout_width="wrap_content" 25 android:layout_height="wrap_content" 26 android:text="ログインして始める" 27 android:id="@+id/ToLogin" 28 android:layout_below="@+id/NewUserSet" 29 android:layout_centerHorizontal="true" 30 android:layout_marginTop="59dp" /> 31 32 <EditText 33 android:layout_width="wrap_content" 34 android:layout_height="wrap_content" 35 android:inputType="textPassword" 36 android:ems="10" 37 android:id="@+id/Password" 38 android:layout_above="@+id/NewUserSet" 39 android:layout_alignRight="@+id/ToLogin" 40 android:layout_alignEnd="@+id/ToLogin" /> 41 42 <TextView 43 android:layout_width="wrap_content" 44 android:layout_height="wrap_content" 45 android:textAppearance="?android:attr/textAppearanceSmall" 46 android:text="Passeword" 47 android:id="@+id/textView" 48 android:layout_above="@+id/Password" 49 android:layout_alignLeft="@+id/Password" 50 android:layout_alignStart="@+id/Password" /> 51 52 <TextView 53 android:layout_width="wrap_content" 54 android:layout_height="wrap_content" 55 android:textAppearance="?android:attr/textAppearanceSmall" 56 android:text="UserName" 57 android:id="@+id/textView2" 58 android:layout_alignParentTop="true" 59 android:layout_alignLeft="@+id/textView" 60 android:layout_alignStart="@+id/textView" /> 61 62 <EditText 63 android:layout_width="wrap_content" 64 android:layout_height="wrap_content" 65 android:inputType="textPersonName" 66 android:ems="10" 67 android:id="@+id/UserName" /> 68 69</RelativeLayout> 70 71

ActivitySecond.java

java

1package ncmbdataquick.mbaas.com.nifty.datastorequickstart; 2 3import android.app.Activity; 4import android.app.AlertDialog; 5import android.content.Intent; 6import android.os.Bundle; 7import android.support.design.widget.FloatingActionButton; 8import android.support.design.widget.Snackbar; 9import android.support.v7.app.AppCompatActivity; 10import android.support.v7.widget.Toolbar; 11import android.view.View; 12import android.widget.Button; 13 14import com.nifty.cloud.mb.core.DoneCallback; 15import com.nifty.cloud.mb.core.NCMB; 16import com.nifty.cloud.mb.core.NCMBException; 17import com.nifty.cloud.mb.core.NCMBObject; 18 19import javax.security.auth.callback.PasswordCallback; 20 21public class ActivitySecond extends Activity { 22 @Override 23 protected void onCreate(Bundle savedInstanceState) { 24 super.onCreate(savedInstanceState); 25 setContentView(R.layout.activity_activity_second); 26 27 28 //**************** APIキーの設定とSDKの初期化 ********************** 29 NCMB.initialize(this, ""); 30 31 32 Button sendButton = (Button) findViewById(R.id.ToLogin); 33 sendButton.setOnClickListener(new View.OnClickListener() { 34 35 36 @Override 37 38 39 public void onClick(View v) { 40 Intent intent = new Intent(getApplication(), MainActivity.class); 41 startActivity(intent); 42 43 44 45 } 46 }); 47 } 48 49 50 //このメソッドを呼び出せば、PasswordとUserIdがセットされるようにする。 51 //xmlにonClickでNewUserSetを記入しておく 52 53 public void NewUserSet(View view) { 54 55 //NewUserAddというデータベースのクラス 56 final NCMBObject obj2 = new NCMBObject("NewUserAdd"); 57 //ここをPlanText(TextView)にユーザーが打ち込んだ値にする。 58 obj2.put("Password", Password); 59 obj2.put("UserName",UserName); 60 obj2.saveInBackground(new DoneCallback() { 61 @Override 62 public void done(NCMBException e) { 63 if (e != null) { 64 //保存失敗 65 new AlertDialog.Builder(ActivitySecond.this) 66 .setTitle("Notification from Nifty") 67 .setMessage("Error:" + e.getMessage()) 68 .setPositiveButton("OK", null) 69 .show(); 70 71 } else { 72 //保存成功 73 new AlertDialog.Builder(ActivitySecond.this) 74 .setTitle("Notification from Nifty") 75 .setMessage("Save successfull! with ID:" + obj2.getObjectId()) 76 .setPositiveButton("OK", null) 77 .show(); 78 79 } 80 } 81 }); 82 83 } 84 85 86} 87

どうぞ宜しくお願いします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

Buttonと同様にEditTextをインスタンス化し、EditTextから文字列を取得してください。

また、Androidの基礎から見直したほうがいいですよ。

投稿2016/10/31 06:22

yona

総合スコア18155

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

edoooooo

2016/10/31 06:24

ありがとうございます。 入門書の基礎を見てその機能を追加していこうと思います。
edoooooo

2016/10/31 07:01

//ここに新しく上で宣言した、UserNameとPasswordを(XMLのViewを)取得する。 //この下のR.id.UserNameのところには、何書くべきなのか? mUserName=(EditText)findViewById(R.id.UserName);//ユーザーが入力するUserName mPassword=(EditText)findViewById(R.id.Password);//ユーザーが入力するPassword String userName=mUserName.getText().toString(); String password=mPassword.getText().toString(); obj2.put("Password", password); obj2.put("UserName", userName); このようなコードでサーバーに保存することができました。 ありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.51%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問