ZachtheBoB
ZachtheBoB

Reputation: 400

findViewById must be void but can't make it void

I am trying to use findViewById in my code, but it must be void, what is wrong? I don't want to have the Method clickbutton but if I take it out, it says it must be void. Is there any way I can do this without changing everything in my code?

import android.os.Bundle;
import android.app.Activity;
import android.app.NotificationManager;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ToggleButton;

public class LoginWorker extends Activity implements OnClickListener{


    Button login;
    EditText user, pass;
    ToggleButton repass;
    TextView invail;

    private boolean savelogin = false;

public void clickbutton() {


        login = (Button) findViewById(R.id.bloginf);
        user = (EditText) findViewById(R.id.usernametf);
        pass = (EditText) findViewById(R.id.passwordtf);
        invail = (TextView) findViewById(R.id.invalidinfo);
        repass = (ToggleButton) findViewById(R.id.rememberlogintb);
        login.setOnClickListener(new View.OnClickListener() {


            @Override
            public void onClick(View v) {
                if(user.getText().equals("parents")){
                    if(pass.getText().equals("!saints")){
                        if(repass.isChecked()){
                            savelogin = true;
                            setContentView(R.layout.announcements);
                        }
                    }else if(!repass.isChecked()){
            savelogin = false;
            setContentView(R.layout.announcements);
        }
    }if(!user.getText().equals("pie")){
        invail.setText("Invalid Username and / or Password!");
    }if(!pass.getText().equals("!pie")){
        invail.setText("Invalid Username and / or Password!");
    }
}
}); 
}
}

Thanks for your time!

Upvotes: 0

Views: 84

Answers (3)

Code_Insanity
Code_Insanity

Reputation: 2648

You need this code. Try watching some YouTube videos to help with the process of understanding what all this does.

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

   //All of your apps code goes here.  
} 

Upvotes: 0

Su  Zhenpeng
Su Zhenpeng

Reputation: 224

where is your onCreate ,you must call it and setContentView(R.layout.***);

Upvotes: 1

Shobhit Puri
Shobhit Puri

Reputation: 26027

You are missing the onCreate function it seems. onCreate is Called when the activity is starting. This is where most initialization should go. Have all the above code you have inside this onCreate function. Before going further you should study the activity lifecycle. i.e what happens when an activity is created and in which order the functions are called. This will tell you how to implement what you want. Also as @vikram suggested a tutorial would help you to start.

Upvotes: 3

Related Questions