请大家帮忙解决一下在Eclipse中Android制作登陆界面的问题
LoginActivity.java如下:
public class LoginActivity extends Activity {
private EditText username,password;
private Button login,reset;
private RadioGroup radioGroup=null;
private RadioButton radioButton1,radioButton2;
private String userNameValue,passwordValue;
private RadioGroup radioBtton1;
private RadioGroup radioBtton2;
public static Teachers teacher=new Teachers();
public static Students student=new Students();
@SuppressLint({ "WorldReadableFiles", "NewApi" })
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
radioGroup=(RadioGroup) findViewById(R.id.radioGroup);
radioBtton1=(RadioGroup) findViewById(R.id.radioButton1);
radioBtton2=(RadioGroup) findViewById(R.id.radioButton2);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_login); //加载设计界面
System.out.println("onCreate方法被执行");
username=(EditText)this.findViewById(R.id.username);
password=(EditText)this.findViewById(R.id.password);
login=(Button)this.findViewById(R.id.btn_login);
reset=(Button)this.findViewById(R.id.btn_reset);
login.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//获取账号和密码
String susername=username.getText().toString();
String spassword=password.getText().toString();
System.out.println("susername-->"+username+" spassword-->"+spassword);
if(radioButton1.isChecked()==true){
///////////////连接服务器////////////////////////////////
String HTTPCustomer="http://10.150.24.111:8080/score_login/LoginAndroid?username="+susername+"&password="+spassword;
HttpGet httpRequest=new HttpGet(HTTPCustomer);
System.out.println("chenggong");
try{
System.out.println("cheng11");
HttpResponse httpResponse=new DefaultHttpClient().execute(httpRequest);
System.out.println("cheng");
if(httpResponse.getStatusLine().getStatusCode()==200){
byte[] data=new byte[1024];
data=EntityUtils.toByteArray(httpResponse.getEntity());
ByteArrayInputStream in=new ByteArrayInputStream(data);
DataInputStream din=new DataInputStream(in);
int count=din.readInt();
System.out.println("count-->"+count);
if(count>0){//表示登录成功
teacher.sette_id(din.readInt());
teacher.sette_password( din.readUTF());
teacher.sette_name(din.readUTF());
teacher.sette_birthday(din.readUTF());
teacher.sette_phone(din.readUTF());
teacher.sette_sex( din.readUTF());
teacher.sette_salary(din.readUTF());
teacher.sette_title(din.readUTF());
teacher.sette_department(din.readUTF());
Toast.makeText(LoginActivity.this,"登录成功", Toast.LENGTH_SHORT).show();
//跳转界面
Intent intent = new Intent(LoginActivity.this,FirstActivity.class);
LoginActivity.this.startActivity(intent);
//finish();
intent.putExtra("un", susername);
intent.putExtra("ps", spassword);
LoginActivity.this.startActivity(intent);
}else{
Toast toast=Toast.makeText(LoginActivity.this, "登录失败",Toast.LENGTH_SHORT);
toast.show();
}
din.close();
in.close();
}
} catch(ClientProtocolException e){
e.printStackTrace();
} catch(IOException e){
e.printStackTrace();
}
}else{
if(radioButton2.isChecked()==true){
String HTTPCustomer="http://10.150.24.111:8080/score_login/LoginAndroid?username="+susername+"&password="+spassword;
HttpGet httpRequest=new HttpGet(HTTPCustomer);
System.out.println("chenggong");
try{
System.out.println("cheng11");
HttpResponse httpResponse=new DefaultHttpClient().execute(httpRequest);
System.out.println("cheng");
if(httpResponse.getStatusLine().getStatusCode()==200){
byte[] data=new byte[1024];
data=EntityUtils.toByteArray(httpResponse.getEntity());
ByteArrayInputStream in=new ByteArrayInputStream(data);
DataInputStream din=new DataInputStream(in);
int count=din.readInt();
System.out.println("count-->"+count);
if(count>0){//表示登录成功
student.setStu_id(din.readInt());
student.setStu_password(din.readUTF());
student.setStu_name(din.readUTF());
student.setStu_birthday(din.readUTF());
student.setStu_phone(din.readUTF());
student.setStu_sex(din.readUTF());
student.setCla_id(din.readInt());
student.setStu_major(din.readUTF());
student.setStu_grade(din.readUTF());
student.setStu_department(din.readUTF());
Toast.makeText(LoginActivity.this,"登录成功", Toast.LENGTH_SHORT).show();
//跳转界面
Intent intent = new Intent(LoginActivity.this,FirstActivity.class);
LoginActivity.this.startActivity(intent);
//finish();
}else{
Toast toast=Toast.makeText(LoginActivity.this, "登录失败",Toast.LENGTH_SHORT);
toast.show();
}
din.close();
in.close();
}
} catch(ClientProtocolException e){
e.printStackTrace();
} catch(IOException e){
e.printStackTrace();
}
}
}
}
});
reset.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
username.setText("");
password.setText("");
}
});
}
}