使用SetOnClick Listener使我以前的活动登录按钮不可点击



这是我的登录按钮功能:

这个功能只是在点击按钮时验证用户,但当我使用onClick时方法中,此按钮停止工作。

public void onClick(View view) {
        user_string = usernameText.getText().toString();
        pass_string = passwordText.getText().toString();
        Vibrator myVib;
        myVib = (Vibrator) this.getSystemService(VIBRATOR_SERVICE);
        myVib.vibrate(50);
        ref.authWithPassword(user_string, pass_string, authResultHandler);

        switch (view.getId()) {
            case R.id.back_login_button:
                finish();
                break;
        }
    }

这是另一个活动(片段)onCreate函数

这是另一个片段的构造函数,这只是将数据发送到firebase

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_admin);
        //firebase part
        initializefirebase();
        //casting
        Team_name = (EditText) findViewById(R.id.teamname_text);
        Category = (EditText) findViewById(R.id.actv_category);
        Lab_alloted = (EditText) findViewById(R.id.actv_lab);
        Table_alloted = (EditText) findViewById(R.id.actv_table);
        judgedby = (EditText) findViewById(R.id.actv_judge);
        final Firebase fire = new Firebase(db_url);

以下是OnClickListener方法

        save.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v){
                participant_data participant = new participant_data();
                participant.setTeamName(Team_name.getText().toString());
                participant.setCategory(Category.getText().toString());
                participant.setJudjed_by(judgedby.getText().toString());
                participant.setLab_alloted(Lab_alloted.getText().toString());
                participant.setTable_alloted(Table_alloted.getText().toString());

                fire.child("Participants Data by admin:").setValue(participant);
                Team_name.setText("");
                Category.setText("");
                judgedby.setText("");
                Lab_alloted.setText("");
                Table_alloted.setText("");
                Toast.makeText(getApplicationContext(), "Data Send Successfully", Toast.LENGTH_SHORT).show();

            }
         });
         //onclick listener
        Toolbar toolbar = (Toolbar) findViewById(R.id.default_toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        AccountHeader headerResult = new AccountHeaderBuilder()
                .withActivity(this)
                .withHeaderBackground(R.drawable.header)
                .addProfiles(
                        new ProfileDrawerItem().withName("Test User").withEmail("TestEmail@gmail.com")).withSelectionListEnabled(false).withProfileImagesVisible(false)
//                .withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() {
//                    @Override
//                    public boolean onProfileChanged(View view, IProfile profile, boolean currentProfile) {
//                        return false;
//                    }
//                })
                .build();
       // new DrawerBuilder().withActivity(this).build();
        PrimaryDrawerItem item1 = new PrimaryDrawerItem().withName("Fill Participants Data").withIcon(GoogleMaterial.Icon.gmd_face);
        PrimaryDrawerItem item2 = new PrimaryDrawerItem().withName("Edit Participants Data").withIcon(GoogleMaterial.Icon.gmd_mode_edit);
        PrimaryDrawerItem item3 = new PrimaryDrawerItem().withName("Fill Judge Data").withIcon(GoogleMaterial.Icon.gmd_publish);
        PrimaryDrawerItem item4 = new PrimaryDrawerItem().withName("Upload Schedule").withIcon(GoogleMaterial.Icon.gmd_publish);
         result = new DrawerBuilder().withSelectedItem(-1)
                .withActivity(this)
                .withToolbar(toolbar)
                .withAccountHeader(headerResult)
                .addDrawerItems(
                        item1,item2,item3
                       // new DividerDrawerItem(),
                       // new DividerDrawerItem(),

                        )
                .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                    @Override
                    public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                        Fragment fragment = null;
                        switch (position) {
                            case 1:
                                fragment = new admin_fragment_data_entry();

                        }
                        if (fragment != null) {
                            FragmentManager fragmentManager = getSupportFragmentManager();
                            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                            fragmentTransaction.addToBackStack(null);
                            fragmentTransaction.add(R.id.container_body, fragment);
                            fragmentTransaction.commit();
                        }
                        return false;
                    }
                }
                )
                .build();
    }

通常,当一个项目有错误代码时,我首先看到的是没有返回语句或结束大括号。选中此项并重新运行您的项目。

由于我无法使用主活动中片段的按钮,因此该片段出现了错误。点击按钮即可实现。

最新更新