How to display count of received message on tab of viewpager with PagerSlidingTabStrip android?

986 views Asked by At

I am building chat application. And in my application i am using View Pager with PagerSlidingTabStrip. below is snapshot.

enter image description here

Now i want to show numeric counter on Recent's tab when ever i received new message from user
enter image description here.

Please help me i am stuck on that point from many days.

Thanks

1

There are 1 answers

0
inhogo On

I did it by custom view. Edit PagerSlidingTabStrip.java file like below.

private void addIconTab(final int position, int resId) {
    LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.image_tab, null);
    ImageButton tab = (ImageButton)view.findViewById(R.id.img_icon);
    tab.setImageResource(resId);
    addTab(position, view);
}

If you use text tab, modify addTextTab() method.

And layout.xml

<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <ImageButton
        android:id="@+id/img_icon"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:contentDescription="@null"
        android:layout_centerInParent="true"
        android:background="@null"
        android:clickable="false" />

    <TextView
        android:id="@+id/tv_count"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="7dp"
        android:background="@drawable/bg_number"
        android:gravity="center"
        android:text="33" />

</RelativeLayout>