基于第一个活动微调器选择的第二个活动微调器显示

时间:2019-11-20 06:34:03

标签: android android-layout android-intent

我的UI具有两个布局,两个活动带有两个微调器和其他按钮。

第一种布局是登录活动,我们将从数据库中选择“ Spinner1”数据,然后按登录“按钮”,将转到下一种布局。

要求为

基于第一个布局(Firstactivity)Spinner1选择第二个布局Spinner2应该更改。

注意:基于Spinner1的Spinner2更改在第二个布局中工作正常。

尝试了不同的方法,但是没有。需要一些专家的意见。

原样

首次版式活动

public class Loginactivity extends Activity {
  Spinner s1, s2, s3, s4, s5;
  Cursor spinner1csr, spinner2csr, spinner3csr, spinner5csr;
  SimpleCursorAdapter sca, sca2, sca3, sca5;
  LoginDataBaseAdapter loginDataBaseAdapter;
  Button login;
  Button registerr;
  EditText enterpassword, et;
  TextView forgetpass;
  String st;
  video_view video_view;
  video_view videoView;
  String TAG = "VideoPlayer";
  private MediaController mediaController;
  DatabaseHandler dbhndlr;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    setContentView(R.layout.login);
    s1 = (Spinner) findViewById(R.id.spinner1);
    s5 = (Spinner) findViewById(R.id.spinner5);
    dbhndlr = new DatabaseHandler(this);
    login = (Button) findViewById(R.id.login_btn);
    registerr = (Button) findViewById(R.id.register_btn);
    enterpassword = (EditText) findViewById(R.id.password_edt);
    forgetpass = (TextView) findViewById(R.id.textView2);
    long spinner1_selected = 0;
    loginDataBaseAdapter = new LoginDataBaseAdapter(getApplicationContext());
    loginDataBaseAdapter.open();

    manageCustomerSpinner();
    final VideoView videoView = (VideoView) findViewById(R.id.videoView2);
    MediaController mediaController = new MediaController(this);
    mediaController.setAnchorView(videoView);

    Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath() + "/DCIM/steprock/steprock.mp4");


    videoView.setMediaController(mediaController);
    videoView.setVideoURI(uri);
    videoView.requestFocus();
    videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
      @Override
      public void onPrepared(MediaPlayer mp) {
        mp.setLooping(true);
        Log.i(TAG, "Duration = " +
          videoView.getDuration());
      }
    });
    videoView.start();

    registerr.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {

        Intent i = new Intent(Loginactivity.this, Registration.class);
        startActivity(i);
      }
    });

    login.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {
        // TODO Auto-generated method stub
        String Password = enterpassword.getText().toString();

        String storedPassword = loginDataBaseAdapter.getSinlgeEntry(Password);

        if (Password.equals(storedPassword)) {
          Toast.makeText(Loginactivity.this, "Congrats: Login Successfully", Toast.LENGTH_LONG).show();
          Intent ii = new Intent(Loginactivity.this, SpinnerEx4Activity.class);

          startActivity(ii);
        } else if (Password.equals("")) {
          Toast.makeText(Loginactivity.this, "Please Enter Your Password", Toast.LENGTH_LONG).show();
        } else {
          Toast.makeText(Loginactivity.this, "Password Incorrect", Toast.LENGTH_LONG).show();
        }
      }
    });
  }
  public void manageCustomerSpinner() {
    spinner5csr = dbhndlr.getCustomers();
    if (sca5 == null) {
      sca5 = new SimpleCursorAdapter(
        this,
        android.R.layout.simple_list_item_2,
        spinner5csr,
        new String[] {
          DatabaseHandler.COL_CUSTOMER_NAME,
            // DatabaseHandler.COL_CUSTOMER_ID
        },
        new int[] {
          android.R.id.text1,
            // android.R.id.text2
        },
        0
      );
      s5.setAdapter(sca5);
      s5.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView << ? > parent, View view, int position, long id) {
          manageLotSpinner(id); //<<<<<<<<<< WHENEVER CUSTOMER IS SELECTED THE LOT SPINNER IS MANAGED >>>>>>>>>>
        }

        @Override
        public void onNothingSelected(AdapterView << ? > parent) {

        }
      });
    } else {
      sca5.swapCursor(spinner5csr);
    }


    forgetpass.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {
        // TODO Auto-generated method stub

        final Dialog dialog = new Dialog(Loginactivity.this);
        dialog.getWindow();
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        //dialog.setContentView(R.layout.forget_search);
        dialog.show();

        final EditText security = (EditText) dialog.findViewById(R.id.securityhint_edt);
        final TextView getpass = (TextView) dialog.findViewById(R.id.textView3);

        //Button ok=(Button)dialog.findViewById(R.id.getpassword_btn);
        Button cancel = (Button) dialog.findViewById(R.id.cancel_btn);


        cancel.setOnClickListener(new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            dialog.dismiss();
          }
        });

        dialog.show();
      }
    });
  }


  @Override
  protected void onDestroy() {
    super.onDestroy();
    // Close The Database
    loginDataBaseAdapter.close();
  }



}

第二个布局微调器详细信息。

 public void manageLotSpinner(long id) {
        spinner2csr = dbhndlr.getLotsPerCustomer1(id);
        if (sca2 == null) {
            sca2 = new SimpleCursorAdapter(
                    this,
                    android.R.layout.simple_list_item_2,
                    spinner2csr,
                    new String[]{
                            DatabaseHandler.ROUTE,
                            //DatabaseHelper.COL_LOT_ID
                    },
                    new int[]{
                            android.R.id.text1,
                            //android.R.id.text2
                    },
                    0
            );
            s1.setAdapter(sca2);
            s1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    manageSpinner3(spinner2csr.getString(spinner2csr.getColumnIndex(DatabaseHandler.ROUTE)));
                }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {

                }
            });

        } else {
            sca2.swapCursor(spinner2csr);
        }
    }

0 个答案:

没有答案