Java 多士元';t在android应用程序上显示,使用android studio
早上好,我试着让祝酒词显示学生人数是少于0还是多于100。除了显示祝酒词外,该应用程序似乎工作正常。这项作业明天晚上到期 这是我的密码:Java 多士元';t在android应用程序上显示,使用android studio,java,android,Java,Android,早上好,我试着让祝酒词显示学生人数是少于0还是多于100。除了显示祝酒词外,该应用程序似乎工作正常。这项作业明天晚上到期 这是我的密码: package co.tekitall.classroommanager; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickLi
package co.tekitall.classroommanager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.util.ArrayList;
import static co.tekitall.classroommanager.R.id.NumOfStudents;
public class Classroom extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_classroom);
Button button = (Button) findViewById(R.id.SubmitClassRoomInfoButton);
}
void ClassroomElements() {
//ArrayList
ArrayList<EditText> arrayList = new ArrayList<>();
arrayList.add((EditText) findViewById(R.id.Teacher_Name));
arrayList.add((EditText) findViewById(R.id.Room_Number));
arrayList.add((EditText) findViewById(R.id.ClassroomHelper));
arrayList.add((EditText) findViewById(R.id.NumOfStudents));
}
OnClickListener listener = new OnClickListener() {
@Override
public void onClick(View v) {
EditText numofstudents = (EditText) findViewById(R.id.NumOfStudents);
String getstucount = numofstudents.getText().toString();
int setstucount = Integer.parseInt(getstucount);
if(setstucount < 0) {
numofstudents.setText("");
Toast toast = Toast.makeText(Classroom.this, "Please try Again! Number must be greater then 0 and less than 100...", Toast.LENGTH_LONG);
toast.show();
}
if(setstucount > 100) {
numofstudents.setText("");
Toast toast = Toast.makeText(Classroom.this, "Please try Again! Number must be greater then 0 and less than 100...", Toast.LENGTH_LONG);
toast.show();
} else
numofstudents.setText("");
Toast toast = Toast.makeText(Classroom.this, "Good Job",
Toast.LENGTH_LONG);
toast.show();
}
};
}
package co.tekitall.classroommanager;
导入android.support.v7.app.AppActivity;
导入android.os.Bundle;
导入android.view.view;
导入android.view.view.OnClickListener;
导入android.widget.Button;
导入android.widget.EditText;
导入android.widget.Toast;
导入java.util.ArrayList;
导入static co.tekitall.classroommanager.R.id.NumOfStudents;
公共课堂活动{
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_教室);
按钮按钮=(按钮)findViewById(R.id.SubmitClassRoomInfoButton);
}
void ClassroomElements(){
//ArrayList
ArrayList ArrayList=新的ArrayList();
add((EditText)findViewById(R.id.Teacher_Name));
arrayList.add((EditText)findViewById(R.id.Room_编号));
add((EditText)findViewById(R.id.ClassroomHelper));
add((EditText)findViewById(R.id.NumOfStudents));
}
OnClickListener=新的OnClickListener(){
@凌驾
公共void onClick(视图v){
EditText numofstudents=(EditText)findViewById(R.id.numofstudents);
字符串getstucount=numofstudents.getText().toString();
int setstucount=Integer.parseInt(getstucount);
如果(设置计数<0){
numofstudents.setText(“”);
Toast Toast=Toast.makeText(教室。这个“请重试!数字必须大于0且小于100…”,Toast.LENGTH_LONG);
toast.show();
}
如果(设置计数>100){
numofstudents.setText(“”);
Toast Toast=Toast.makeText(教室。这个“请重试!数字必须大于0且小于100…”,Toast.LENGTH_LONG);
toast.show();
}否则
numofstudents.setText(“”);
Toast Toast=Toast.makeText(class.this,“干得好”,
吐司长度(长);
toast.show();
}
};
}
看起来您有一个按钮
和一个OnClickListener
,但您从未将它们连接在一起。例如:
button.setOnClickListener(listener);
看起来您有一个
按钮
和一个OnClickListener
,但您从未将它们连接在一起。例如:
button.setOnClickListener(listener);
您需要使用绑定
按钮
和侦听器
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_classroom);
Button button = (Button) findViewById(R.id.SubmitClassRoomInfoButton);
button.setOnClickListener(listener);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^
}
加上使用if
和else if
而不是多个if
s,因为一个数字只能小于0
或者大于100或者介于|等于0或100之间
if(setstucount < 0){//...code}
else if(setstucount > 100){//...code}
else {//...code}
if(setstucount<0){/…code}
如果(setstucount>100){/..code}
else{//…代码}
您需要使用绑定按钮和侦听器
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_classroom);
Button button = (Button) findViewById(R.id.SubmitClassRoomInfoButton);
button.setOnClickListener(listener);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^
}
加上使用if
和else if
而不是多个if
s,因为一个数字只能小于0
或者大于100或者介于|等于0或100之间
if(setstucount < 0){//...code}
else if(setstucount > 100){//...code}
else {//...code}
if(setstucount<0){/…code}
如果(setstucount>100){/..code}
else{//…代码}
我很高兴我能提供帮助,仅供将来参考ClassroomElements()
方法不做任何事情,list
的范围仅在此函数内,不做任何事情。我很高兴我能提供帮助,仅供将来参考ClassroomElements()
方法不做任何事情,list
的范围仅在此函数内,不做任何操作。