0
1
00:00:08,550 --> 00:00:14,850
So now that we've created another activity let's see how we go from our original main activity into
1

2
00:00:14,850 --> 00:00:24,880
the display list items activity and also how can we pass data to this activity. Let's keep working with
2

3
00:00:24,880 --> 00:00:34,120
this event handler over here, so if you remember earlier we attach the event handler on click so let's
3

4
00:00:34,120 --> 00:00:38,480
comment the content out. To comment out,
4

5
00:00:38,500 --> 00:00:45,080
all you need to do is select the lines that you are working with press control and Slash.
5

6
00:00:45,080 --> 00:00:50,890
And this will automatically comment out the lines that you're working with let's start with writing
6

7
00:00:50,890 --> 00:00:51,240
code...
7

8
00:00:51,250 --> 00:00:53,390
Over here.
8

9
00:00:53,460 --> 00:01:00,240
So first jump to the new activity where you're going to use an Intent. Intent.
9

10
00:01:00,500 --> 00:01:04,830
I equals new intent.
10

11
00:01:04,880 --> 00:01:14,070
Don't worry about the red warnings for now pass the context and the class of the intent to jump to. Press
11

12
00:01:14,180 --> 00:01:22,530
Alt and Enter everywhere to fix the errors then we're going to get the text from the edit text like
12

13
00:01:22,530 --> 00:01:24,150
we did earlier.
13

14
00:01:24,210 --> 00:01:38,820
So let's do that define a string list item and call this E T dot get text convert this to string.
14

15
00:01:38,860 --> 00:01:41,970
Now we have our list item.
15

16
00:01:42,130 --> 00:01:48,460
Next we're going to pass the string to the new activity by using put extra to do this.
16

17
00:01:48,460 --> 00:01:55,080
We define a variable with the ID of the item to pass we define it as public.
17

18
00:01:55,080 --> 00:02:04,730
In order to access it from the other class then we just put the value, so put extra uses a sort of key
18

19
00:02:04,730 --> 00:02:14,640
value pair you pass the key then the value, once this is done we just start the activity by running start
19

20
00:02:14,640 --> 00:02:24,630
activity. OK now let's set up what happens when the new activity is opened, first thing is to obtain the
20

21
00:02:24,630 --> 00:02:30,960
string that was passed by the original activity, To do this,
21

22
00:02:30,970 --> 00:02:38,820
define a variable called intent and set it to get intent.
22

23
00:02:38,870 --> 00:02:41,390
Next we define a string.
23

24
00:02:41,420 --> 00:02:47,970
Call it item value then we get the string by writing intent.
24

25
00:02:48,190 --> 00:02:59,090
Dot get string extra and pass the ID by pointing to main activity dot extra item which is what we
25

26
00:02:59,090 --> 00:03:02,030
defined earlier. OK.
26

27
00:03:02,060 --> 00:03:13,870
Now let's go to the UI and let's drop a text to view change the idea to text view list item, now in the
27

28
00:03:13,870 --> 00:03:24,040
activity we can refer to the text to view like we did in the previous section so text view TV equals
28

29
00:03:24,670 --> 00:03:41,020
find view by ID, R dot ID dot text view list item then we will change the text of the text view by writing
29

30
00:03:41,680 --> 00:03:54,490
TV dot set text and pass the item value we obtained earlier. OK so let's run this now if we enter text
30

31
00:03:55,750 --> 00:04:03,400
click the button and as you can see we have a new activity opened and the content from the edit text
31

32
00:04:03,520 --> 00:04:07,170
was passed on to the new activity.
32

33
00:04:07,360 --> 00:04:13,090
Another thing we can do is add a back button in order to have the activity go to the previous activity,
33

34
00:04:14,210 --> 00:04:26,800
to do this we edit the manifest and add Android colon parent activity name equals dot main activity
34

35
00:04:28,580 --> 00:04:40,730
and in the metadata we need to add Android colon name equals Android dot support dot parent underscore
35

36
00:04:40,820 --> 00:04:51,520
activity and Android colon value equals dot main activity.
36

37
00:04:51,580 --> 00:05:02,090
Now when we run it again add text click the button and here you can see we have a back button in the
37

38
00:05:02,090 --> 00:05:05,990
activity which sends us back to the original activity.
