A
A
AlexRuch2015-03-07 16:45:12
Java
AlexRuch, 2015-03-07 16:45:12

Android. How to access the elements of an Activity from a third-party class?

Situation:
class 1-activity2
There is a ListView with items.
When you click on an element, it goes to the corresponding activity, but now everything works on crutches (crutches and bicycles. We program as best we can), i.e. Each element has its own activation.
class2-Activity2
(in TextView activity)
...
classN-ActivityN
Q:
How can I access an activity of another class?
Those. there will be 2 classes (containing lv and a class containing data about the selected element).
And from the first class values ​​for another will be set.
...
switch (position){
case 0:
//set the value tv from class1 for the activity bound to class2
Intent intent =new Intent (class1.this, class2.class )
startActivity(intent);
break;
case1:
//set the value of the same tv
...
}
Not banned in Google. Didn't find anything of note.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
one pavel, 2015-03-07
@AlexRuch

if I understand correctly, you need to pass the value when you click on an item in the ListeView to another activity, then
for this the android creators came up with a mechanism that is described in detail in the tutorials.
developer.android.com/training/basics/firstapp/sta...
pass value
intent.putExtra(EXTRA_MESSAGE, message);
get in another activity
String message = intent.getStringExtra(MyActivity.EXTRA_MESSAGE);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question