Professional Documents
Culture Documents
Functionality UI design
&
Advanced UI features Look n Feel of the App
Activity
Android Widgets
Button
EditText
ImageView
ImageButton
INPUT OUTPUT
Android Intents
provides runtime
binding
Parameters
Context
extras
putExtra
public void sendMessage(View view) {
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
Receive Intent
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
XML codes
<OpeningTag
PropertyName=“value”
PropertyName=“value”
PropertyName=“value”
PropertyName=“value”
>
</ClosingTag>
XML codes
<OpeningTag <Button
PropertyName=“value” android:id="@+id/btngenrefnumber”
PropertyName=“value” android:layout_width="fill_parent“
PropertyName=“value” android:layout_height="wrap_content"
APK FILE
Android App Deployment
Android 4 Major building blocks
Get your hands Dirty
Let’s Start
Building!
Android Activity
What makes up an activity
XML Layouts
Java Class
OnCreate Method
<activity android:name=".Startmenu"></activity>
<activity android:name=".About"></activity>
<activity android:name=".Help"></activity>
</application>
<uses-sdk android:minSdkVersion="8" />
</manifest>
"textCapSentences“
Normal text keyboard that capitalizes the first
letter for each new sentence.
EditText Widget
On XML
Controlling other Behaviors
"textCapWords“
Normal text keyboard that capitalizes every
word. Good for titles or person names.
"textAutoCorrect“
Normal text keyboard that corrects commonly
misspelled words.
EditText Widget
On XML
Controlling other Behaviors
"textPassword“
Normal text keyboard, but the characters
entered turn into dots.
"textMultiLine“
Normal text keyboard that allow users to input
long strings of text that include line breaks
(carriage returns).
EditText Widget
On XML
<EditText
android:id="@+id/postal_address"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/postal_address_hint“
android:inputType=
"textPostalAddress|textCapWords|textNoSuggestions" />
EditText Widget
On Java
OR
EditText myedittext;
EditText Widget
On Java
Use findViewById
EditText myedittext=(EditText)findViewById(R.id.edttext);
Add Cast to specify
EditText
the type ofWidget
View
On Java
EditText Widget
On Java
Assign to a variable
String textToshare=myedittext.getText().toString();
TextView Widget
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content“
android:text="GoSocial"/>
TextView Widget
On Java
OR
TextView mytextview;
TextView Widget
On Java
Use findViewById
TextView mytextview=(TextView)findViewById(R.id.textview1);
Assign to a variable
String textToshare=mytextview.getText().toString();
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
Button Widget
Button Widget
On XML
<Button
android:id="@+id/btngo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Go"/>
Button Widget
On Java
Create a widget(Button) Java object
OR
Button mybutton;
Button Widget
On Java
Use findViewById
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
});
Button Click Event
On Java
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
} Button Click Event
On Java
Button Click Event
On Java
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content“ android:layout_height="wrap_content“
android:text=“Send” android:text=“Next”
[ButtonClicked]
public void ButtonClicked(View v){
switch (v.getId()) {
case R.id.btn1:
break;
case R.id.btn2:
break;
default:
break;
}
}
Android Toast
Android Toast
On Java
Implementation of Toast on Android Activity
Parameters
Context
Message
Duration
Toast.makeText(getApplicationContext(), "Hello!",
Toast.LENGTH_LONG).show();
Android Intents
Functions of Intents are:
Connect Activities
Bundle bundle=getIntent().getExtras();
String item=bundle.getString("itemselected");
Android Intents
Launch another Application
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>
</menu>
Android Options Menu
On XML-Menu Folder
Id
android:id="@+id/action_settings"
orderInCategory
android:orderInCategory="1"
Android Options Menu
On XML-Menu Folder
OnCreateOptionsMenu
To display an optionsmenu
OnOptionsItemSelected
Handle events when one item of the optionsmenu is
selected
Android Options Menu
On Java
OnCreateOptionsMenu
To display an optionsmenu
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflate=getMenuInflater();
inflate.inflate(R.menu.main_activity_actions, menu);
return true;
} Android Options Menu
On Java
Android Options Menu
On Java
OnOptionsItemSelected
Handle events when one item of the optionsmenu is selected
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case R.id.settings:
Toast.makeText(getApplicationContext(), “Settings clicked", Toast.LENGTH_LONG).show();
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
Android Options Menu
On Java
Android AppBar
Android ListView
Android ListView
On XML
ListView
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
Data Source
Can be an Array, External File or data from Database
ArrayAdapter
ArrayAdapter<String> adapter;
Reference to a ListView
ListView mylistview=(ListView) findViewById(R.id.listView1);
Listener
onItemClickListener
Android ListView
On Java
Key Tags
Tabhost
TabWidget
FrameLayout
LinearLayout
Android Tabs
TabHost
FrameLayout1 FrameLayouts
12
Android Tabs
On Java
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/intro_text"/>
</ScrollView>
Android ScrollView
On XML
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/intro_text"/>
</LinearLayout>
</ScrollView>
Android AlertDialog
Android AlertDialog
Android AlertDialog
Icon
Title
Negative
Message Button
Neutral
Positive Button
Button
5
Android AlertDialog
Android InputDialog
Android SeekBar Widget
Android Date Picker
Android Time Picker