在一个EditText问题中有6个整数?

时间:2014-05-21 14:38:16

标签: java android eclipse

我创建了(累到......)一个抽奖程序,该程序要求用户在一个EditText中输入6个号码,另一个"幸运号码"在另一个EditText中,如果数字遵循几个条件,它们将出现在同一个TextView中。 我的问题是我不确定我是否正确地将整数插入到EditText中,因为当我运行程序时它出现在模拟器中但不会对我在EditText中写的内容作出反应。有人可以查看我的代码并告诉我我做错了什么吗?

头等舱:

package com.example.hm195;


import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


public class MainActivity extends Activity {
class layout{
    public void layout(){
        Nums = (EditText)findViewById(R.id.etNums);
        Lnum = (EditText)findViewById(R.id.etLuckyNum);
        btn = (Button)findViewById(R.id.btn1);
        Result = (TextView)findViewById(R.id.tvResult);
    }
    EditText Nums, Lnum;
    Button btn;
    TextView Result;
}
class events {
    public void events(){
        l.btn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                n.valid();

            }
        });
    }
}
nums n;
layout l;
events e;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    l = new layout();
    e = new events();
}

}

第二课:     包com.example.hm195;

import android.app.Activity;
import android.widget.Toast;

public class nums {
/*int a, int b, int c, int d, int e, int f, int g*/
MainActivity main;

 int a, b, c, d, e, f, g;
public void valid(){
     main.l.Nums.setText(a + "," + b + "," + c + "," + d + "," + e + "," + f);
     main.l.Lnum.setText(g);

    if ( a < 1 || a >37 || b < 1 || b >37 || c < 1 || c >37 || d < 1 || d >37 || e < 1 || e >37 || f < 1 || f >37) {
        Toast.makeText(main, "One or more of your six numbers is lower than 1 or higher than 37", 1).show();
        if (g < 1 || g > 7 ) {
        Toast.makeText(main, "Your lucky number is lower than 1 or higher than 7", 1).show();
        }
    }else {
        main.l.Result.setText(main.l.Nums.getText().toString() + " " + main.l.Lnum.getText().toString()); 
    }
}
}

XML:          

<EditText
    android:id="@+id/etNums"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10" >

    <requestFocus />
</EditText>

<EditText
    android:id="@+id/etLuckyNum"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10" />

<Button
    android:id="@+id/btn1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" />

<TextView
    android:id="@+id/tvResult"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="TextView" />

</LinearLayout>

0 个答案:

没有答案