cyc115
cyc115

Reputation: 645

Android Studio Button onClick : Cannot resolve symbol

I am experiencing some really wired things lately with Android Studio, In my Login fragment xml I have defined a Button and a TextView. Both the button and the textView are suppose to be clickable. However only the switchToSignUp method is resolvable in the xml file. when I try to assign onClick listenr for the Button I get a warning that says : Cannot resolve symbol "loginClick". The code compiles fine even if the warning exists however when I click the Button nothing happens. Am I missing something obvious or could it be a bug of the Android Studio ?

<Button
    android:text="login"
    android:onClick="loginClick"
    android:id="@+id/loginBtn"
    style="@android:style/Widget.Holo.Button.Borderless"
    android:background="@android:color/holo_red_light"
...
/>
<TextView
    android:text="No account ?"
    android:id="@+id/singin_signup_tv"
    android:clickable="true"
    android:onClick="switchToSignUp"
    ...
 />

here is how I have defined the onClick listeners :

public void switchToSignUp(View view){
    Log.i(TAG,"switch to sign up ");
    switchView();
}

public void loginClick(View view){
    Log.i(TAG,"login clicked");
    new AsyncTask<String , Void , String>(){
        protected String doInBackground(String... params) {/*...*/  }
    }.execute("");
}

Upvotes: 3

Views: 14384

Answers (1)

cyc115
cyc115

Reputation: 645

As @CarlosJimenes has mentioned I have to assign the onClick Listener in the onCreateView () method of the LoginFragment class.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container , Bundle savedInstanceState){
    inputView =  inflater.inflate(R.layout.fragment_login,
            container,
            false
    );
    Button btn = (Button) inputView.findViewById(R.id.loginBtn);
    btn.setOnClickListener( loginClicked );
    return inputView;
}

Upvotes: 4

Related Questions