1

私はAndroidプログラミングが初めてで、Javaプログラミングがあまり得意ではありません。ここでの簡単な質問:ボタンが押されたら、EditText に入力された値を配列に格納する方法、各インデックスを別の変数の定数値と比較できるようにする方法。

4

2 に答える 2

2
//your array
String[n] array;

//your button
Button b;

///your edittext
EditText e;

if(b.isPressed())
array[x]=edit.getText().toString();

またはArrayListを使用

ArrayList<String> n= new ArrayList<String>();

//your button
Button b;

///your edittext
EditText e;


if(b.isPressed())
n.add(edit.getText().toString());
于 2012-08-12T01:48:51.647 に答える
0

これは非常に簡単です。xml レイアウト

 <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/relativeLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
 <EditText
         android:id="@+id/txtField"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent" />
 <Button
         android:id="@+id/button"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"/>
</RelativeLayout>

したがって、アクティビティで次のように入力します。

EditText text = (EditText) findViewById(R.id.txtField);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {

    public void onClick(View v) {
          String s = text.getText().toString();
              // then you do whatever you like with it
    }
});
于 2012-08-12T01:55:34.567 に答える