PageIndicator of greendroid can not display

464 Views Asked by At

my code is:

MainActivity.cpp

i just define a button to test the pageindicator and the code is simple. click button and the pageindicator change the dot

package com.example.androidlab;

import greendroid.widget.PageIndicator;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
    int i = 0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final Button btn = (Button) findViewById(R.id.btn);
        final PageIndicator pi = (PageIndicator) findViewById(R.id.pi);
        pi.setDotCount(5);
        pi.setActiveDot(0);
        btn.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                pi.setActiveDot((++i) % 5);
            }
        });
    }
}

activity_main.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <greendroid.widget.PageIndicator
        android:id="@+id/pi"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </greendroid.widget.PageIndicator>

</LinearLayout>

i use android 2.3.1 sdk

who can help me... thanks

3

There are 3 best solutions below

0
jaredzhang On

refer to this link , how about changing android:layout_width="match_parent" to android:layout_width="wrap_content" .

0
minibigboss On

I have the same exact problem. I don't know why this is happening, but for some reason myPI.getDotDrawable() is returning a null.

I verifired that the styles do exist in the source code and the jar file.

I'm checking it out to figure out what's wrong, although on eclipse layout preview window, the dots do show up.

Solution:

In your activity, add the following:

setTheme(com.cyrilmottier.android.greendroid.R.style.Theme_GreenDroid_NoTitleBar);

before setContentView(...)

Works like a charm now :)

0
Kimo_do On

Just add this item in you AppThem in styles.xml:

<style name="AppTheme" parent="AppBaseTheme">
    <item name="gdPageIndicatorStyle">@style/GreenDroid.Widget.PageIndicator</item>
     <!-- Now no need to set Theme_GreenDroid in your activity  -->
</style>