I have a TextView in ClassA.java :
TextView txt1 = (TextView) findViewById(R.id.txt1);
I want to use the value of this TextView in ClassB.java How can i do this?
I have a TextView in ClassA.java :
TextView txt1 = (TextView) findViewById(R.id.txt1);
I want to use the value of this TextView in ClassB.java How can i do this?
To get String from TextView:
TextView txtView = (TextView) findViewById(R.id.your_id_here);
String text = txtView.getText().toString();
Option A If you want to pass data through activities you can use putExtra(). Syntax (ClassA):
@Override onCreate(Bundle savedInstanceState){
...
Intent intent = new Intent(this, ClassB.class);
intent.putExtra("value", "Your text from TextView" );
Then, you have to get it in ClassB. Syntax:
Intent source = getIntent();
String textFromClassA = source.getStringExtra("value");
Option B Initialize string as static and public.
public static String ...
Then you can easly access data from this variable.