I write code and it look ok. I dont know what is the reson that I get ERROR when I write setOnClickListener(this) all I want is to create button in fragment.
"Error:(25, 78) error: incompatible types: void cannot be converted to Button" "Error:Execution failed for task ':android:compileDebugJava'.
Compilation failed; see the compiler error output for details."
Many Thanks for any Help
the source code:
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;
import com.popthejam.game.android.R;
public class Wellcome extends Fragment implements View.OnClickListener {
private Button btnLOGIN ;
public Wellcome() {
// Required empty public constructor
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_wellcome,container,false);
btnLOGIN = (Button) view.findViewById(R.id.btnLogin).setOnClickListener(this);
return view;
}
public void onClick(View view) {
Toast.makeText(getActivity(), "LOGIN BUTTON PRESS", Toast.LENGTH_SHORT).show();
}
}
----
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="@drawable/popthejam"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="fragment.Wellcome">
<TextView
android:gravity="center"
android:textSize="@dimen/profile_entry_text_size"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/welcome_to_app" />
<Button
android:id="@+id/btnLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@android:color/holo_orange_dark"
android:text="Login"
/>
</FrameLayout>