Android从Activity转移到FragmentActivity

时间:2014-03-11 16:29:39

标签: android android-fragments

我创建了一个具有登录页面的应用程序。登录页面连接到php以验证用户。如果输入了有效的详细信息,我希望能够移动到扩展FragmentActivity的滑动标签页。但是,如果我不在我的清单中,它会崩溃。但是,如果我确实包括这个,它会改变我的登录页面的外观,当用户点击登录时,它什么都不做。

public class Login extends Activity {
    Button login;
    EditText username, password;
    TextView message, registerHere, forgot;
    HttpPost httppost;
    StringBuffer buffer;
    HttpResponse response;
    HttpClient httpclient;
    List<NameValuePair> nameValuePairs;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.loginpage);

        login = (Button) findViewById(R.id.login);
        username = (EditText) findViewById(R.id.username);
        password = (EditText) findViewById(R.id.password);
        message = (TextView) findViewById(R.id.message);
        registerHere = (TextView) findViewById(R.id.registerHere);
        forgot = (TextView) findViewById(R.id.forgot);

        login.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                login();
            }
        });

        registerHere.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                startActivity(new Intent(Login.this, Register.class));
            }
        });

        forgot.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                startActivity(new Intent(Login.this, Forgot.class));
            }
        });

    }

    void login() {
        try {

            httpclient = new DefaultHttpClient();
            httppost = new HttpPost("http://192.168.0.8/Coffee_PHP/login.php");
            nameValuePairs = new ArrayList<NameValuePair>(2);
            nameValuePairs.add(new BasicNameValuePair("username", username
                    .getText().toString().trim()));
            nameValuePairs.add(new BasicNameValuePair("password", password
                    .getText().toString().trim()));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            response = httpclient.execute(httppost);
            ResponseHandler<String> responseHandler = new BasicResponseHandler();
            final String response = httpclient.execute(httppost,
                    responseHandler);


            if (response.equalsIgnoreCase("User Found")) {
                startActivity(new Intent(Login.this, MainActivity.class));
            }

            else {
                message.setText("Incorrect Login Details. Please try again.");
                username.setText("");
                password.setText("");
            }

        } catch (Exception e) {
            System.out.println("Exception : " + e.getMessage());
        }
    }
}

0 个答案:

没有答案