android sub activity to draw chart

134 views Asked by At

I am new to android development and facing a problem with activity and sub activity. I have a horizontal scroll view in my application where i display 6 images each for 6 functionalities. When i click on each image i call a sub activity with an intent and draw a chart using achartengine library in the layout that is displayed above the scroll view images. Now my problem is when i click on 2nd image nothing happens. I want to know how i can return to main activity after drawing the chart and be able to listen to click event of other images.

Here is my code.

MainActivity class
 mImage = (ImageView)findViewById(R.id.imageviewapp1);
  mImage.setOnClickListener(new View.OnClickListener() {
      public void onClick(View v) {
         Intent intent;

          intent =  new Intent(AppSuite.this, DrawBarChart.class);
          intent.putExtra("AppName","app1");
          startActivity(intent);
      }
  });
  mImage = (ImageView)findViewById(R.id.imageviewApp2);
  mImage.setOnClickListener(new View.OnClickListener() {
      public void onClick(View v) {

         intent =  new Intent(AppSuite.this, DrawLineChart.class);
          intent.putExtra("AppName","app2");
          startActivity(intent);

      }
  });
  mImage = (ImageView)findViewById(R.id.imageviewapp3);
  mImage.setOnClickListener(new View.OnClickListener() {
      public void onClick(View v) {
         intent =  new Intent(AppSuite.this, DrawCombinedChart.class);
          intent.putExtra("AppName","app3");
          startActivity(intent);
      }
  });



The chart is drawn when i click on first image but if i click on 2nd image the control doesn't go back to main activity where i have on click listensers for other images.


     sub activity class

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.landing);

    final LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
    layout.removeAllViewsInLayout();

    GraphicalView chartView  = ChartFactory.getBarChartView(DrawBarChart.this, dataset, mRenderer, BarChart.Type.DEFAULT);

    layout.addView(chartView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

please see the image attached.

enter image description here

1

There are 1 answers

0
sonic On

Your second button is in the background activity. This is why you can not interact with it. If you press the back button, it will close the second activity and goes back to the first.

But you should probably use fragments. In your main activity you could have a layout with all your buttons, and un fragment with your chart. When the user press a button, you will be able to pass data to the chart