Move from one type of activity to another

I am trying to transfer a view from one activity to another.

In my first action onButtonClick, I move on to another action using Intent.

I wrote this line setContentView(R.layout.main);in the 1st operation, and also announced graphView.

Now the problem is what I want to fill graphViewin the second step, but this link, i.e. mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot);is present in the 1st activity.

So how can I use mySimpleXYPlotin 2nd activity?

if i use

 setContentView(R.layout.main);
 mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot);

in the second step, the whole layout restarts, and I don’t want to do this :(

ANY HELP WILL BE RECOGNIZED!

+5
source share
2

xml . , xml .

0

, , .

...

1st :

public class MyActivity1 extends Activity{
    public static XYPlot mySimpleXYPlot;

    public onCreated(Bundle b){
       setContentView(R.layout.main);
       mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot);
       // start you 2nd activity from button
    }
}

Activity2

public class MyActivity2 extends Activity{
    private XYPlot mySimpleXYPlot;
    public onCreated(Bundle b){
       setContentView(R.layout.main); 
       mySimpleXYPlot = MyActivity2.mySimpleXYPlot;
       // use mySimpleXYPlot as per your requirement
    }
}

, , ,

Edit2

xml, oncreate time

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
   xmlns:android="http://schemas.android.com/apk/res/android"   
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:orientation="vertical"
   android:id="@+id/main_linear"
   >
  <Button android:id="@+id/btn1" android:text="Click" android:layout_width="wrap_content"
      android:layout_height="wrap_content" />
</LinearLayout>

    public static EditText edittext;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test);
    //edittext = (EditText) findViewById(R.id.edittext);
    final LinearLayout ll = (LinearLayout) findViewById(R.id.main_linear);

    edittext = new EditText(getApplicationContext());
    edittext.setId(1);
    edittext.setText("text change");
    ((Button)findViewById(R.id.btn1)).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            edittext.setText(edittext.getText().toString());
            ll.removeView(edittext);
            startActivity(new Intent(TestLinear.this,TestClass.class));
        }
    });
    ll.addView(edittext);
}

,

    private static EditText edittext;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test);
    LinearLayout ll = (LinearLayout) findViewById(R.id.main_linear);
    getEdit();
    ((Button)findViewById(R.id.btn1)).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.v("test", edittext.getText().toString());
        }
    });
    ll.addView(edittext);
}
static void  getEdit(){
    edittext = TestLinear.edittext;
}

, . - , , setter/getter

+1

All Articles