//Activity 1
public void onClick(View arg0) {
long value;
if (tinhthanh == 0) {
value = 1;
}
else {
value = 0;
}
Bundle sendBundle = new Bundle();
sendBundle.putLong("value", value);
Intent i = new Intent(VNTaxiCallActivity.this, ListTaxi.class);
i.putExtras(sendBundle);
startActivity(i);
overridePendingTransition( R.anim.slide_in_left, R.anim.slide_out_left );
}
//Activity 2
Bundle receiveBundle = this.getIntent().getExtras();
final long int_tinhthanh = receiveBundle.getLong("value");
lblHeader = (TextView) findViewById(R.id.lblHeaderCity);
if(int_tinhthanh==1){
Taxi_HaNoi();
} else if (int_tinhthanh==2) {
Taxi_DaNang();
} else if (int_tinhthanh==3) {
Taxi_HCM();
}else {
Taxi_CanTho();
}
Showing posts with label android exam code customer listview ImageView Animation DatePicker Dialog Example Radio Buttons DisplayMetrics exam Favorite HTML View. Show all posts
Showing posts with label android exam code customer listview ImageView Animation DatePicker Dialog Example Radio Buttons DisplayMetrics exam Favorite HTML View. Show all posts
Wednesday, October 26, 2011
sort abc listview adapter android exam
java.util.Arrays.sort(arrListCity, java.text.Collator.getInstance(new Locale("vi")));
Friday, September 23, 2011
Android Threads, Handlers and AsyncTask - Tutorial
Threads
Android supports standard Java Threads . You can use standard Threads and the
tools from the package "java.util.concurrent" to put actions into the background.
The only limitation is that you cannot directly update the UI from the a
background process. See Java Concurrency Tutorial for an introduction into
background processing with standard Java.
If you need to update the UI from a background task you need to use some Android
specific classes. You can use the class "android.os.Handler" for this or the class
"AsynTasks".
AsyncTask
The class AsyncTask encapsulates the creation of Threads and Handlers.
You must implement the method "doInBackground()", which defines what action
should be done in the background. This method is be automatically run in a
separate Thread. To update the UI you can override the method "onPostExecute()".
This method will be called by the framework once your action is done and runs
within the UI thread. AsynTask
To use AsyncTask you must subclass it. AsynTask uses generics and varargs.
The parameters are the following AsyncTask . TypeOfVarArgParams is passed into the doInBackground(),
ProgressValueis used for progress information and ResultValue must be returned
from doInBackground() and is passed to onPostExecute() as parameter.
Android AsyncTask Example
Today I was working on a loading screen for an Android app.
The purpose of the loading screen is to report to the user which boot up
processes were happening as well as provide a nice looking intro screen
for the app. The U.I. layer of an Android app runs in a single thread.
You can think of a thread as a stack of function calls. Each function
in the list executes only after the one before it has completed.
This is a very simplistic view of a thread but for the sake of this post
it will work. With multiple processor intensive functions stacked up the U.I.
layer can become inactive and appear to hang while waiting for the stack to
finish. This problem can be solved by splitting up the processes into
separate threads. By doing so your U.I. layer can update concurrent with the
other more intensive processes.
The Android operating system provides a couple of solutions to this problem.
The solution I implemented for the loading screen was a class called AsyncTask
. It’s a wrapper for a threaded operation that provides some really convenient
callbacks for updating progress information and handling task completion.
Link Download
create webservice php with android exam
create web service php sever configureWSDL('hellowsdl',$ns);
$server->wsdl->schemaTargetNamespace=$ns;
// register a web service method
$server->register('ws_add',
array('int1' => 'xsd:integer','int2' => 'xsd:integer'), // input parameters
array('total' => 'xsd:integer'), // output parameter
$ns, // namespace
"$ns#ws_add", // soapaction
'rpc', // style
'encoded', // use
'adds two integer values and returns the result' // documentation
);
function ws_add($int1, $int2){
return new soapval('return','xsd:integer', ($int1 + $int2));
}
$server->register('hello', // method name
array('name' => 'xsd:string'), // input parameters
array('return' => 'xsd:string'), // output parameters
'urn:hellowsdl', // namespace
'urn:hellowsdl#hello', // soapaction
'rpc', // style
'encoded', // use
'Says hello to the caller' // documentation
);
function hello($name) {
return 'Hello, ' . $name;
}
// service the methods
$server->service($HTTP_RAW_POST_DATA);
?>
Android clien call webservice
package vn.softech.android;
import java.util.Vector;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class ClientCallWebServicesActivity extends Activity {
private static final String SOAP_ACTION = "urn:hellowsdl#hello";
private static final String METHOD_NAME = "hello";
private static final String NAMESPACE = "urn:hellowsdl";
private static final String URL = "http://192.168.73.177/nusoap/server.php";
// private Object resultRequestSOAP = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
// SoapObject
request.addProperty("name", "Le Hong Vu");
//call method ws_add
//request.addProperty("int1", 3);
//request.addProperty("int2", 4);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(URL);
httpTransport.debug = true;
try {
httpTransport.call(SOAP_ACTION, envelope);
Object response = envelope.getResponse();
Log.i("WSClient Result", response.toString());
}
catch (Exception exception) {
Log.i("WSClient", exception.toString());
}
}
}
Link Downloadhttp://www.ziddu.com/download/16485069/XMLRPCAndroidclient.rar.html
Thursday, September 22, 2011
How to create an option menu (F2)
package co.cc;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
public class ContextMenu extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
super.onCreateOptionsMenu(menu);
createMenu(menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
return MenuChoice(item);
}
private void createMenu(Menu menu) {
MenuItem mni1 = menu.add(0, 0, 0, "About");
{
mni1.setAlphabeticShortcut('a');
mni1.setIcon(R.drawable.about);
}
MenuItem mni2 = menu.add(0, 1, 1, "Exit");
{
mni2.setAlphabeticShortcut('x');
mni2.setIcon(R.drawable.exit);
}
}
private boolean MenuChoice(MenuItem item) {
switch (item.getItemId()) {
case 0:
setContentView(R.layout.about);
return true;
case 1:
super.finish();
return true;
}
return false;
}
}
F2 display menu context optionClick About display content about
Link Download
http://www.ziddu.com/download/16472331/ContextMenuAndroid.rar.html
Android Progress Dialog Example
package co.cc;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.os.Bundle;
public class AsyntaskActivity extends Activity {
protected static final int LOADING_DIALOG = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
showDialog(LOADING_DIALOG);
}
protected Dialog onCreateDialog(int id) {
if(id == LOADING_DIALOG){
ProgressDialog loadingDialog = new ProgressDialog(this);
loadingDialog.setMessage("Loading records ...");
loadingDialog.setIndeterminate(true);
loadingDialog.setCancelable(true);
return loadingDialog;
}
return super.onCreateDialog(id);
}
}
connect internet with android exam
note use emulator
setting -> network-> wireless–>airplane==true
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.i("connect", "connect-internet");
if(isOnline()==false)
{
Log.i("connect", "isOnline()");
Log.i("connect", "No connect");
}
else
{}
}
public boolean isOnline() {
Context context = getApplicationContext();
ConnectivityManager connectivity = (ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
return false;
} else {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {
for (int i = 0; i < info.length; i++) {
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
}
return false;
}AndroidManifest.xml<uses-permission android:name=”android.permission.INTERNET”></uses-permission>
<uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE”></uses-permission>
Tab Layout Android exam download
To create a tabbed UI, you need to use a
You can implement your tab content in one of two ways: use the tabs to swap
In this tutorial, you'll create a tabbed UI that uses a separate

Link download
http://www.ziddu.com/download/16471970/tabhost.rar.html
TabHost and a TabWidget. The TabHost must be the root node for the layout, which contains both the TabWidget for displaying the tabs and a FrameLayout for displaying the tab content.You can implement your tab content in one of two ways: use the tabs to swap
Views within the same Activity, or use the tabs to change between entirely separate activities. Which method you want for your application will depend on your demands, but if each tab provides a distinct user activity, then it probably makes sense to use a separate Activity for each tab, so that you can better manage the application in discrete groups, rather than one massive application and layout.In this tutorial, you'll create a tabbed UI that uses a separate
Activity for each tab.- Start a new project named HelloTabWidget.
- First, create three separate
Activityclasses in your project:ArtistsActivity,AlbumsActivity, andSongsActivity. These will each represent a separate tab. For now, make each one display a simple message using aTextView. For example:public class ArtistsActivity extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView textview = new TextView(this); textview.setText("This is the Artists tab"); setContentView(textview); } }
Notice that this doesn't use a layout file. Just create aTextView, give it some text and set that as the content. Duplicate this for each of the three activities, and add the corresponding<activity/>tags to the Android Manifest file.
- You need an icon for each of your tabs. For each icon, you should create two versions: one for when the tab is selected and one for when it is unselected. The general design recommendation is for the selected icon to be a dark color (grey), and the unselected icon to be a light color (white). (See the Icon Design Guidelines.) For example:
For this tutorial, you can copy these images and use them for all three tabs. (When you create tabs in your own application, you should create customized tab icons.)
Now create a state-list drawable that specifies which image to use for each tab state:
- Save the icon images in your project
res/drawable/directory. - Create a new XML file in
res/drawable/namedic_tab_artists.xmland insert the following:<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <!-- When selected, use grey --> <item android:drawable="@drawable/ic_tab_artists_grey" android:state_selected="true" /> <!-- When not selected, use white--> <item android:drawable="@drawable/ic_tab_artists_white" /> </selector>
This is a state-list drawable, which you will apply as the tab image. When the tab state changes, the tab icon will automatically switch between the images defined here.
- Save the icon images in your project
- Open the
res/layout/main.xmlfile and insert the following:<?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp"> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp" /> </LinearLayout> </TabHost>
This is the layout that will display the tabs and provide navigation between eachActivitycreated above.
TheTabHostrequires that aTabWidgetand aFrameLayoutboth live somewhere within it. To position theTabWidgetandFrameLayoutvertically, aLinearLayoutis used. TheFrameLayoutis where the content for each tab goes, which is empty now because theTabHostwill automatically embed eachActivitywithin it.
Notice that theTabWidgetand theFrameLayoutelements have the IDstabsandtabcontent, respectively. These names must be used so that theTabHostcan retrieve references to each of them. It expects exactly these names.
- Now open
HelloTabWidget.javaand make it extendTabActivity:public class HelloTabWidget extends TabActivity {
- Use the following code for the
onCreate()method:public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Resources res = getResources(); // Resource object to get Drawables TabHost tabHost = getTabHost(); // The activity TabHost TabHost.TabSpec spec; // Resusable TabSpec for each tab Intent intent; // Reusable Intent for each tab // Create an Intent to launch an Activity for the tab (to be reused) intent = new Intent().setClass(this, ArtistsActivity.class); // Initialize a TabSpec for each tab and add it to the TabHost spec = tabHost.newTabSpec("artists").setIndicator("Artists", res.getDrawable(R.drawable.ic_tab_artists)) .setContent(intent); tabHost.addTab(spec); // Do the same for the other tabs intent = new Intent().setClass(this, AlbumsActivity.class); spec = tabHost.newTabSpec("albums").setIndicator("Albums", res.getDrawable(R.drawable.ic_tab_albums)) .setContent(intent); tabHost.addTab(spec); intent = new Intent().setClass(this, SongsActivity.class); spec = tabHost.newTabSpec("songs").setIndicator("Songs", res.getDrawable(R.drawable.ic_tab_songs)) .setContent(intent); tabHost.addTab(spec); tabHost.setCurrentTab(2); }
This sets up each tab with their text and icon, and assigns each one anActivity.
A reference to theTabHostis first captured withgetTabHost(). Then, for each tab, aTabHost.TabSpecis created to define the tab properties. ThenewTabSpec(String)method creates a newTabHost.TabSpecidentified by the given string tag. For eachTabHost.TabSpec,setIndicator(CharSequence, Drawable)is called to set the text and icon for the tab, andsetContent(Intent)is called to specify theIntentto open the appropriateActivity. EachTabHost.TabSpecis then added to theTabHostby callingaddTab(TabHost.TabSpec).
At the very end,setCurrentTab(int)opens the tab to be displayed by default, specified by the index position of the tab.
Notice that not once was theTabWidgetobject referenced. This is because aTabWidgetmust always be a child of aTabHost, which is what you use for almost all interaction with the tabs. So when a tab is added to theTabHost, it's automatically added to the childTabWidget.
- Now open the Android Manifest file and add the
NoTitleBartheme to the HelloTabWidget's<activity>tag. This will remove the default application title from the top of the layout, leaving more space for the tabs, which effectively operate as their own titles. The<activity>tag should look like this:<activity android:name=".HelloTabWidget" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar">
- Run the application.
Link download
http://www.ziddu.com/download/16471970/tabhost.rar.html
not screen horizontal android exam
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0" package="softech.mobile">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<activity android:name="softech.mobile.activity.AiLaTrieuPhuActivity"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="portrait"
> <intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Subscribe to:
Posts (Atom)