Question

My question is that I had from days back, my graphic of androidPlot running good, I sad all data inside of graphic in a simple layout, but, I incorporate a library "Viewpagerindicator" for to do better the relation of entry and exit of money, then, It's working all, just that now not see the elements inside of graphic, here a image Click here

"Ingreso" and "Egreso" are two layout that I add in my principal layout, are two activitys, I didn't touch anything in my class of graphic "Egreso" or "Ingreso", just add them. I don't understand why I don't see it.

I think that is something in my tag of viewpager in my principal laoyut, because, I use this in other layout simple, I see the graphic. Please help. Adjunct my code.

the principal layout (acitivity_movimientos.xml)

<com.viewpagerindicator.TitlePageIndicator
    android:id="@+id/indicator"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    style="@style/CustomTitlePageIndicator"/>



<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    android:paddingBottom="5dp"
    android:paddingLeft="8dp"
    android:paddingRight="8dp"
    android:paddingTop="5dp" />

activity_movimiento_ingresos.xml

<com.androidplot.xy.XYPlot
    android:id="@+id/grafica_ingresos"
    android:layout_width="fill_parent"
    android:layout_height="200dp" 
    android:layout_marginTop="10dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    androidPlot.title="Ingresos de Enero"
    androidPlot.domainLabel="Dias"
    androidPlot.rangeLabel="Ingresos"/>

My class MovimientosActivity.java

public class MovimientosActivity extends Activity {

private ViewPager viewPager;

private LinearLayout ingresos;
private LinearLayout egresos;

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_movimientos);

    getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#008AFF")));
    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setAdapter(new MainPageAdapter());

    TitlePageIndicator titleIndicator = (TitlePageIndicator)findViewById(R.id.indicator);

    //TabPageIndicator titleIndicator = (TabPageIndicator)findViewById(R.id.indicator);
    titleIndicator.setViewPager(viewPager);     
    titleIndicator.setOnPageChangeListener(new OnPageChangeListener() {

        @Override
        public void onPageSelected(int position){}

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels){}

        @Override
        public void onPageScrollStateChanged(int state){}
    });     

}

class MainPageAdapter extends PagerAdapter
{

    @Override
    public CharSequence getPageTitle(int position) 
    {
        String title = null;

        switch (position)
        {
        case 0:
            title = getString(R.string.ingresos);
            break;
        case 1:
            title = getString(R.string.egresos);
            break;
        }
        return title;
    }

    @Override
    public int getCount()
    {
        return 2;
    }

    @Override
    public Object instantiateItem(ViewGroup collection, int position)
    {
        View page = null;
        switch (position)
        {
        case 0:
            if (ingresos == null)
            {
                ingresos = (LinearLayout) LayoutInflater.from(MovimientosActivity.this).inflate(R.layout.activity_movimiento_ingresos, null);
            }
            page = ingresos;
            break;
        case 1:
            if (egresos == null)
            {
                egresos = (LinearLayout) LayoutInflater.from(MovimientosActivity.this).inflate(R.layout.activity_movimiento_egresos, null);
            }
            page = egresos;
            break;
        }

        ((ViewPager) collection).addView(page, 0);

        return page;
    }

    @Override
    public boolean isViewFromObject(View view, Object object)
    {
        return view == object;
    }

    @Override
    public void destroyItem(View collection, int position, Object view)
    {
        ((ViewPager) collection).removeView((View) view);
    }

My class MovimientoIngresoActivity.java

public class MovimientoIngresosActivity extends Activity {

private XYPlot plot;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_movimiento_ingresos);

    plot = (XYPlot) findViewById(R.id.grafica_ingresos);

    //CREAMOS DOS ARREGLOS PARA MOSTRAR LOS DATOS, SUSTITUIR POR DATOS REALES LUEGO
    Number[] series1Numeros = {1, 8, 5, 2, 7, 4};
    Number[] series2Numeros = {4, 6, 3, 8, 2, 10};
    Number[] series3Numeros = {3, 5, 7, 4, 6, 8};

    //AÑADIMOS LINEA 1
    XYSeries series1 = new SimpleXYSeries(
            Arrays.asList(series1Numeros), //ARRAY, VALORES VERTICALES, NOMBRE DE LA LINEA
            SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Intereses");

    //AÑADIMOS LINEA 2
    XYSeries series2 = new SimpleXYSeries(
            Arrays.asList(series2Numeros), //ARRAY, VALORES VERTICALES, NOMBRE DE LA LINEA
            SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Alquileres");

    //AÑADIMOS LINEA 3
    XYSeries series3 = new SimpleXYSeries(
            Arrays.asList(series3Numeros), //ARRAY, VALORES VERTICALES, NOMBRE DE LA LINEA
            SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Sansiones");

    //MODIFICAMOS LOS COLORES DE LA PRIMERA SERIE
    LineAndPointFormatter series1Format = new LineAndPointFormatter(
            Color.rgb(0, 200, 0),       //COLOR LINEA
            Color.rgb(0, 100, 0),       //COLOR DEL PUNTO
            null, null);  //RELLENO

    //LO AÑADIMOS AL PANEL
    plot.addSeries(series1, series1Format);

    //MODIFICAMOS LOS COLORES DE LA SEGUNDA SERIE
    LineAndPointFormatter series2Format = new LineAndPointFormatter(
        Color.rgb(0, 0, 200),       //COLOR LINEA
        Color.rgb(0, 0, 100),       //COLOR DEL PUNTO
        null, null);  //RELLENO

    //LO AÑADIMOS AL PANEL
    plot.addSeries(series2, series2Format);

    //MODIFICAMOS LOS COLORES DE LA SEGUNDA SERIE
    LineAndPointFormatter series3Format = new LineAndPointFormatter(
        Color.rgb(200, 0, 0),       //COLOR LINEA
        Color.rgb(100, 0, 0),       //COLOR DEL PUNTO
        null, null);  //RELLENO

    //LO AÑADIMOS AL PANEL
    plot.addSeries(series3, series3Format);

}

}

Thanks

Was it helpful?

Solution

Actually u are not drawing the graph, ur MovimientoIngresosActivity is useless here. U will need to make few changes like this.

1.Create a method to draw the graph

View getGraph()
{
    LinearLayout view = (LinearLayout) LayoutInflater.from(MovimientosActivity.this)
            .inflate(R.layout.activity_movimiento_ingresos, null);
XYPlot plot = (XYPlot) view.findViewById(R.id.grafica_ingresos);

//CREAMOS DOS ARREGLOS PARA MOSTRAR LOS DATOS, SUSTITUIR POR DATOS REALES LUEGO
Number[] series1Numeros = {1, 8, 5, 2, 7, 4};
Number[] series2Numeros = {4, 6, 3, 8, 2, 10};
Number[] series3Numeros = {3, 5, 7, 4, 6, 8};

//AÑADIMOS LINEA 1
XYSeries series1 = new SimpleXYSeries(
        Arrays.asList(series1Numeros), //ARRAY, VALORES VERTICALES, NOMBRE DE LA LINEA
        SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Intereses");

//AÑADIMOS LINEA 2
XYSeries series2 = new SimpleXYSeries(
        Arrays.asList(series2Numeros), //ARRAY, VALORES VERTICALES, NOMBRE DE LA LINEA
        SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Alquileres");

//AÑADIMOS LINEA 3
XYSeries series3 = new SimpleXYSeries(
        Arrays.asList(series3Numeros), //ARRAY, VALORES VERTICALES, NOMBRE DE LA LINEA
        SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Sansiones");

//MODIFICAMOS LOS COLORES DE LA PRIMERA SERIE
LineAndPointFormatter series1Format = new LineAndPointFormatter(
        Color.rgb(0, 200, 0),       //COLOR LINEA
        Color.rgb(0, 100, 0),       //COLOR DEL PUNTO
        null);  //RELLENO

//LO AÑADIMOS AL PANEL
plot.addSeries(series1, series1Format);

//MODIFICAMOS LOS COLORES DE LA SEGUNDA SERIE
LineAndPointFormatter series2Format = new LineAndPointFormatter(
    Color.rgb(0, 0, 200),       //COLOR LINEA
    Color.rgb(0, 0, 100),       //COLOR DEL PUNTO
    null);  //RELLENO

//LO AÑADIMOS AL PANEL
plot.addSeries(series2, series2Format);

//MODIFICAMOS LOS COLORES DE LA SEGUNDA SERIE
LineAndPointFormatter series3Format = new LineAndPointFormatter(
    Color.rgb(200, 0, 0),       //COLOR LINEA
    Color.rgb(100, 0, 0),       //COLOR DEL PUNTO
    null);  //RELLENO

//LO AÑADIMOS AL PANEL
plot.addSeries(series3, series3Format);
    return plot;

}

2.change the instantiateItem method to

@Override
    public Object instantiateItem(ViewGroup collection, int position)
    {
        View page = null;
        switch(position)
        {
        case 0:
            page = getGraph();
            break;
        case 1:
            page = getGraph();
            break;
        }
        ((ViewPager) collection).addView(page, 0);
        return page;
    }

U may need to make different methods for different graph.

U can also do it by using fragments and FragmentPagerAdapter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top