Note that there are some explanatory texts on larger screens.

plurals
  1. POSpinner to String to Intent to Array . Why won't this Intent work?
    primarykey
    data
    text
    <p>Why won't the intent work properly? MainActivity is a graph that originally plotted one of the lines from an array (series1Numbers).I have another class (Main2Activity) with a spinner that i would like to have populate the (series1numbers) Array in MainActivity thereby generating my graph. Currently the graph line for (series1numbers) is blank which makes alot of sense because i have not been able to figure out how to populate it with the single number from (Main2Activity). I have searched and searched and not been able to connect the dots for this issue.</p> <p>Main Activity.java</p> <pre><code>package com.example; import java.util.Arrays; import android.app.Activity; import android.content.Intent; import android.graphics.Color; import android.os.Bundle; import com.androidplot.series.XYSeries; import com.androidplot.xy.LineAndPointFormatter; import com.androidplot.xy.SimpleXYSeries; import com.androidplot.xy.XYPlot; /** * The simplest possible example of using AndroidPlot to plot some data. */ public class MainActivity extends Activity { private XYPlot mySimpleXYPlot; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Intent intename = getIntent(); String name = (String) intename.getSerializableExtra("series1Numbers"); // initialize our XYPlot reference: mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot); // Create a couple arrays of y-values to plot: Number[] series1Numbers ={name}; Number[] series2Numbers = {-4, -4, -5, -4, -4, -4, -3, -7, -4, -2, -4, -5, -5, -5}; // Turn the above arrays into XYSeries': XYSeries series1 = new SimpleXYSeries(Arrays.asList(series1Numbers), // SimpleXYSeries takes a List so turn our array into a List SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, // Y_VALS_ONLY means use the element index as the x value "Series1"); // Set the display title of the series // same as above XYSeries series2 = new SimpleXYSeries(Arrays.asList(series2Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Series2"); // Create a formatter to use for drawing a series using LineAndPointRenderer: LineAndPointFormatter series1Format = new LineAndPointFormatter( Color.rgb(0, 200, 0), // line color Color.rgb(0, 100, 0), // point color null); // fill color (none) // add a new series' to the xyplot: mySimpleXYPlot.addSeries(series1, series1Format); // same as above: mySimpleXYPlot.addSeries(series2, new LineAndPointFormatter(Color.rgb(0, 0, 200), Color.rgb(0, 0, 100), null)); // reduce the number of range labels mySimpleXYPlot.setTicksPerRangeLabel(3); // by default, AndroidPlot displays developer guides to aid in laying out your plot. // To get rid of them call disableAllMarkup(): mySimpleXYPlot.disableAllMarkup(); </code></pre> <p>}</p> <p>Main2Activity.java</p> <pre><code>package com.example; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Spinner; import android.widget.TextView; import android.widget.AdapterView.OnItemSelectedListener; public class Main2Activity extends Activity implements OnItemSelectedListener { //TextView series1Numbers ; Spinner spin; String[] series1Numbers = { "-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8" , "-9" , "-10" }; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main2); //series1Numbers = (TextView) findViewById(R.id.series1Numbers ); Spinner spin = (Spinner) findViewById(R.id.spinner); spin.setOnItemSelectedListener(this); ArrayAdapter&lt;String&gt; aa = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_item, series1Numbers); spin.setAdapter(aa); } @Override public void onItemSelected(AdapterView&lt;?&gt; parent, View v, int position, long id) { // TODO Auto-generated method stub // series1Numbers .setText(items[position]); if (position == 1){ Intent intentObj = new Intent(Main2Activity.this, MainActivity.class); intentObj.putExtra("series1Numbers", series1Numbers); startActivity(intentObj); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload