Closed ravigupta9363 closed 8 years ago
Can you post some code? xml where you declare view in layout and code where you find it by id and set listener + listener's code too.
My Layout File ::
<CoordinateLayout>
<android.support.v4.view.ViewPager
android:id="@+id/fragment_recipe_page_view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="256dp"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:id="@+id/fragment_recipe_page_youtube_player">
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/fragment_recipe_page_imageview1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:src="@drawable/image_eight"
app:layout_collapseMode="parallax" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/image_gradient"/>
</FrameLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="parallax"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<ImageButton
android:paddingRight="4dp"
android:id="@+id/fragment_recipe_page_image_button1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@mipmap/back_arrow"
android:background="@android:color/transparent" />
<TextView
android:padding="2dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/fragment_recipe_page_textview0"
android:textSize="18sp"
android:textColor="@color/white"
android:gravity="center"
android:textStyle="bold"
android:text="@string/fragment_recipe_page_textview0" />
</android.support.v7.widget.Toolbar>
<ImageButton
android:layout_width="35dp"
android:layout_height="35dp"
android:background="@drawable/round_button"
android:layout_gravity="right"
android:layout_marginRight="15dp"
android:layout_marginTop="60dp"
android:src="@mipmap/play"
android:id="@+id/fragment_recipe_page_image_button2"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:layout_gravity="bottom|center"
android:layout_marginBottom="95dp"
android:text="@string/fragment_recipe_page_button1"
android:textSize="18sp"
android:id="@+id/fragment_recipe_page_button1"
android:textAllCaps="false"/>
<io.techery.properratingbar.ProperRatingBar
android:id="@+id/layout_fragment_recipe_page_rating_bar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="26sp"
android:textStyle="bold"
app:prb_defaultRating="4"
android:gravity="right"
app:prb_symbolicTick="★"
android:layout_marginBottom="70dp"
android:layout_centerVertical="true"
app:prb_symbolicTickNormalColor="@color/ratingBarEmpty"
app:prb_symbolicTickSelectedColor="@color/ratingBarSelected"
app:prb_totalTicks="5"
app:prb_tickSpacing="1dp"
android:layout_gravity="bottom|center" />
<android.support.design.widget.TabLayout
android:id="@+id/fragment_recipe_page_tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:tabGravity="fill"
android:fitsSystemWindows="true"
app:tabIndicatorColor="@color/white"
app:tabMode="scrollable"
app:tabIndicatorHeight="3dp"
app:tabTextColor="@color/background"
app:tabSelectedTextColor="@color/white">
</android.support.design.widget.TabLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
My Fragment Java File
@Bind(R.id.layout_fragment_recipe_page_rating_bar1) io.techery.properratingbar.ProperRatingBar ratingBar;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_recipe_page, container, false);
rootView = view;
ButterKnife.bind(this, view);
ratingBar.setListener(ratingListener);
viewPager.setAdapter(new RecipePageTabLayoutAdapter(getActivity().getSupportFragmentManager()));
tabLayout.setupWithViewPager(viewPager);
setTextInTabLayout();
return view;
}
private RatingListener ratingListener = new RatingListener() {
@Override
public void onRatePicked(ProperRatingBar ratingBar) {
Toast.makeText(mainActivity, "I am Clicked"+ ratingBar.getRating(), Toast.LENGTH_SHORT).show();
Log.v(Constants.TAG,ratingBar.getRating()+"My Name is Ravi");
}
};
Please add this attribute to your rating bar definition in xml:
app:prb_clickable="true"
As for now this is required for view to be clickable.
I don't remember if it is described in README.md.
I will also modify code to set this to true
when listener is added.
Thanx, it worked
Re-opened due to enhancement needed: set clickable to true
programmatically once listener is attached.
Implemented in 0.0.3
Hi, how can I add the listener to my adapter since when I add it it gives nullpointer exception to the adapter? I tried attaching it on createview as ravigupta9363 above did but it gives me a null pointer exception
@ratemo please show me some code - I suggest some incorrect setup but I can't point out mistake if I do not see source.
P. S.: we have this element working just perfectly fine in adapter
I have followed all your instruction but seems that rating is not changing when I click it, I guess click listener is not working, I don't know why. can you help?