Android: Tp3: Part1: Tabhost
Android: Tp3: Part1: Tabhost
APPING-MASTERS-2013-VERDIER
Android: TP3
Part1: TabHost
We want to create an application with 2 tabs containing the following screens:
PAGE 1 OF 8
ANDROID: SESSION-3
APPING-MASTERS-2013-VERDIER
The ids are really important because the TabHost requires them, so you cant use whatever you want.
ANDROID: SESSION-3
APPING-MASTERS-2013-VERDIER
Now that you have the activity you can create the first_tab.xml layout file.
In the onCreate() method in your activity you have to inflate your view with the SetContentView()
method.
Do
the
same
procedure
for
the
SecondTabActivity
and
the
second_tab.xml
layout.
PAGE 3 OF 8
ANDROID: SESSION-3
APPING-MASTERS-2013-VERDIER
and you have to add the following code to your onCreate() method:
Resources res = getResources();
TabHost mTabHost = getTabHost();
mTabHost.addTab(mTabHost
.newTabSpec("tab_home")
.setIndicator("First", res.getDrawable(R.drawable.ic_launcher))
.setContent( new Intent(this,
fr.epita.tabproject.tabs.FirstTabActivity.class)));
mTabHost.setCurrentTab(0);
You should now be able to launch your application with the first tab.
Add
the
second
tab
to
the
UI.
PAGE 4 OF 8
ANDROID: SESSION-3
APPING-MASTERS-2013-VERDIER
ANDROID: SESSION-3
APPING-MASTERS-2013-VERDIER
button
the height is the height of its content
the width takes all the space left between the labels
the top from the first button is aligned with the labels top
the bottom from the last button is aligned with the labels bottom
If you change your rendering target inside your layout editor, the layout must adapt it self.
PAGE 6 OF 8
ANDROID: SESSION-3
APPING-MASTERS-2013-VERDIER
Part 1: PalindromeChecker
The goal of this exercise is to check in real time if a user inputed string is a palindrome.
PAGE 7 OF 8
ANDROID: SESSION-3
APPING-MASTERS-2013-VERDIER
Step 2: TextWatcher
To check if the input string is a palindrome and to display the character count, we want to be notified
each time it is modified. To do this, your activity has to implements TextWatcher interface.
public class MainActivity extends Activity implements TextWatcher
Youll also have to set the listener on your TextEdit with the addTextChangedListener() method.
We will be working in the afterTextChanged method. This method is called each time the text is
modified.
In this method, check if the textEdit contains a palindrome, count the characters it contains and update
your UI.
PAGE 8 OF 8