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 回答