setVisibility连接MYSQL

时间:2019-06-23 13:22:06

标签: android

这样的问题有两个按钮,NRJ和AVTORADIO默认情况下,它们都是隐藏的。如何进行设置,例如,当NRJ值出现在数据库中时,出现NRJ按钮。或出现AVTORADIO和AVTORADIO按钮。有两个活动,一个带有入口,第二个应该出现这些按钮

Public class MainActivity extends AppCompatActivity {

EditText key;
Button login;
ProgressDialog progressDialog;
ConnectionClass connectionClass;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    key = (EditText) findViewById(R.id.key);
    login = (Button) findViewById(R.id.login);

    connectionClass = new ConnectionClass();

    progressDialog = new ProgressDialog(this);

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


}

public class Logins extends AsyncTask<String, String, String> {

    String keystr = key.getText().toString();
    String z = "";
    boolean success = false;

    String ks, nem, act, fam, rad;

    @Override
    protected void onPreExecute() {
        progressDialog.setMessage("Загрузка...");
        progressDialog.show();

        super.onPreExecute();
    }

    @Override
    protected String doInBackground(String... params) {

        if (keystr.trim().equals(""))
            z = "Вы не ввели ключ";
        else
            {
            try {
                Connection con = connectionClass.CONN();
                if (con == null) {
                    z = "Вы не подключены к интеренут";
                } else {
                    String query = " select * from clients where keyss='" + keystr + "' and Activen = '1'";
                    Statement stmt = con.createStatement();
                    ResultSet rs = stmt.executeQuery(query);
                    while (rs.next()) {

                        ks = rs.getString(1);
                        nem = rs.getString(2);
                        act = rs.getString(5);
                        fam = rs.getString(3);
                        rad = rs.getString(6);


                        if (ks.equals(keystr)) {
                            success = true;
                            z = "Добро пожаловать";
                        } else
                            success = false;
                    }
                }
            }
            catch (Exception ex) {
                success = false;
                z = "Exceptions" + ex;
            }
        }
        return z; }

    @Override
    protected void onPostExecute(String s) {
        Toast.makeText(getBaseContext(), "" + z, Toast.LENGTH_LONG).show();


        if (success) {

            Intent intent = new Intent(MainActivity.this, ActivityTwo.class);

            intent.putExtra("keyss", keystr);
            intent.putExtra("firstnames", nem);
            intent.putExtra("lastname", fam);
            intent.putExtra("RadioStantia", rad);


            startActivity(intent);
        }
        progressDialog.hide();
    }
}
}

ActivityTWO

    public class ActivityTwo extends AppCompatActivity {

TextView nametext;
ConnectionClass connectionClass;
ProgressDialog progressDialog;
ImageButton nrj;
private boolean success = false;
int keyss;
String ks, nem, act, fam, rad, keystr;

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


    progressDialog = new ProgressDialog(this);

    connectionClass = new ConnectionClass();
    nrj = (ImageButton) findViewById(R.id.NRJ);

    Intent intent = getIntent();
    Bundle bundle = intent.getExtras();


    if (bundle != null) {
        keyss = bundle.getInt("keyss");
    }

    String name = getIntent().getStringExtra("firstnames");
    String lastname = getIntent().getStringExtra("lastname");
    String radio = getIntent().getStringExtra("RadioStantia");

    nametext = (TextView) findViewById(R.id.firstname2);

    nametext.setText("Здравствуйте, " + name);

}
}

0 个答案:

没有答案