0

我在这里遇到问题你能帮帮我吗?我很喜欢这个应用程序关于测验。现在你看到的第一件事是类别,这是类:

package com.laurenswuytsjordipapen.cultural.pursuit;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.Button;

import com.laurenswuytsjordipapen.cultural.pursuit.library.UserFunctions;

public class DashboardActivity extends Activity {
    UserFunctions userFunctions;
    Button btnLogout;
    Button btnEuropa;
    Button btnAmerika;
    Button btnAfrika;
    Button btnAzie;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        /**
         * Dashboard Screen for the application
         * */        
        // Check login status in database
        userFunctions = new UserFunctions();
        if(userFunctions.isUserLoggedIn(getApplicationContext())){
            setContentView(R.layout.dashboard);
            btnLogout = (Button) findViewById(R.id.btnLogout);
            btnEuropa = (Button) findViewById(R.id.btnEuropa);
            btnAmerika = (Button) findViewById(R.id.btnAmerika);
            btnAfrika = (Button) findViewById(R.id.btnAfrika);
            btnAzie = (Button) findViewById(R.id.btnAzie);

            btnLogout.setOnClickListener(new View.OnClickListener() {

                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    userFunctions.logoutUser(getApplicationContext());
                    Intent login = new Intent(getApplicationContext(), LoginActivity.class);
                    login.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(login);
                    // Closing dashboard screen
                    finish();
                }
            });
            btnEuropa.setOnClickListener(new View.OnClickListener() {

                public void onClick(View arg0) {

                    Intent start = new Intent(DashboardActivity.this, MainActivity.class);
                    start.putExtra("continent","europa");
                    start.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(start);
                    finish();

                }
            });
            btnAmerika.setOnClickListener(new View.OnClickListener() {

    public void onClick(View arg0) {

        Intent start = new Intent(DashboardActivity.this, MainActivity.class);
        start.putExtra("continent","amerika");
        start.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(start);
        finish();

    }
});
btnAfrika.setOnClickListener(new View.OnClickListener() {

    public void onClick(View arg0) {

        Intent start = new Intent(DashboardActivity.this, MainActivity.class);
        start.putExtra("continent","afrika");
        start.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(start);
        finish();

    }
});
btnAzie.setOnClickListener(new View.OnClickListener() {

    public void onClick(View arg0) {

        Intent start = new Intent(DashboardActivity.this, MainActivity.class);
        start.putExtra("continent","azie");
        start.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(start);
        finish();

    }
}); 


        }else{
            // user is not logged in show login screen
            Intent login = new Intent(getApplicationContext(), LoginActivity.class);
            login.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(login);
            // Closing dashboard screen
            finish();
        }




    }
}

当您第一次打开应用程序并单击类别时,例如:欧洲。你得到所有关于欧洲的问题。当我将类别更改为美国时,您仍然会收到来自欧洲的所有问题。当我清除我的应用程序的数据时,它就结束了。如果我从美国开始,我会收到美国的问题,但如果我换到欧洲,我仍然会收到来自美国的问题。

这是 MainActivity 中的代码:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Bundle extras = getIntent().getExtras();
        if (extras != null) {
         value = extras.getString("continent");
        }



        DBHelper db=new DBHelper(this, value);

这是 DBHelper 中的代码:

String continent;
    String input;
    public DBHelper(Context context, String input) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        continent = input;
    }

然后我用的是得到这些:

if(continent.equals("europa")){
        .....
            }if(continent.equals("amerika")){
....}

你能帮我卡住吗!!

提前致谢!

4

0 回答 0