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

时间:2016-05-07 04:57:09

标签: java android onclicklistener

这是我的登录按钮功能:

此功能只是在按钮点击时对用户进行身份验证,但是当我使用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();

    }

2 个答案:

答案 0 :(得分:0)

通常,当一个项目有错误的代码时,我看的第一个地方是缺少一个return语句,或者结束大括号。检查一下并重新运行您的项目。

答案 1 :(得分:0)

错误与片段有关,因为我无法使用主要活动中片段的按钮。并点击按钮实现。

相关问题