Skip to main content

Posts

Showing posts with the label java

Zoom Animation between Activities in Android

Create an activity and call that activity from the main activity as shown below. MainActivity .class import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MainActivity extends Activity { Button Zoombut; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Zoombut = (Button) findViewById(R.id.button1); Zoombut.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { // TODO Auto-generated method stub Intent i = new Intent(MainActivity.this, success.class); startActivity(i); overridePendingTransition(R.anim.zoom_enter, R.anim.zoom_exit); }}); }} Create a folder in resource and name it as "anim" an create two xmls with the following animation code. Copy and paste the code from below: zoom_...

Simple Gallery Application In Android

Here is simple gallery application.Copy and download the code and try it out..... public class mygalleryactivity extends Activity { Integer[] imageIDs = { R.drawable.pic1, R.drawable.pic2, R.drawable.pic3, R.drawable.pic4, R.drawable.pic5, R.drawable.pic6, R.drawable.pic7 }; Gallery gallery; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); gallery=(Gallery) findViewById(R.id.Gallery01); gallery.setAdapter(new ImageAdapter(this)); gallery.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView parent, View v, int position ,long id) { // TODO Auto-generated method stub Toast.makeText(getBaseContext(), "pic" + (position + 1) + "selected", Toast.LENGTH_SHORT).show(); ImageView imageView =(ImageView) findViewById(R.id.image1); imag...

What is the difference between Services, Thread and an AsyncTask in Android?

Thread Example n ANDROID -- Timer Thread Example Non Runnable States in Multithreading - Different states while thread is in runnable states What is a thread in java ? How to write interfaces in java or Android? More on Android ? Service is like an Activity but has no interface. Probably if you want to fetch the weather for example you won’t create a blank activity for it, for this you will use a Service. A Thread is a Thread, probably you already know it from other part. You need to know that you cannot update UI from a Thread. You need to use a Handler for this, but read further. An AsyncTask is an intelligent Thread that is advised to be used. Intelligent as it can help with it’s methods, and there are two methods that run on UI thread, which is good to update UI components.

Non Runnable States in Multithreading - Different states while thread is in runnable states

See more basics of thread in java here : What is thread in java ? The different states while thread is in runnable states are given below : Sleeping States :   may be alive, but not running  may return to runnable state  stop running for an amount of time  Waiting for Notifications :   wait for notification from other   send to runnable after notified thread Blocked on I/O : after availability of resource sends to runnable Blocked for Joint Completion : waiting for completion of another thread Blocked for Lock Acquistion : Come to this state because of  waiting to acquire the lock of an object.

Parsing an XML from Online in Android

Create a fresh project and name it ParseXMLDemo Then in the ParseXMLDemo.java file copy this code | import java.util.ArrayList; import java.util.HashMap; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import android.app.ListActivity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.SimpleAdapter; import android.widget.Toast; import android.widget.AdapterView.OnItemClickListener; public class ParseXMLDemo extends ListActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ArrayList<String> mylist = new ArrayList<String>(); String xml = ParseXMLMethods.getXML(); Document doc = ParseXMLMethods.XMLfromString(xml); int numResults = ParseXMLMethods.numResults(doc); ...

How to write interfaces in java or Android?

what is an Interface? An interface is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface. An interface is not a class. Writing an interface is similar to writing a class, but they are two different concepts. A class describes the attributes and behaviors of an object. An interface contains behaviors that a class implements. Unless the class that implements the interface is abstract, all the methods of the interface need to be defined in the class. MainActivity.java public class MainActivity extends Activity implements Interface { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public void testFunctionOne() { System.out.println("Print from testFunctionOne in the Interface"); } @Override public void testFunctionTwo() { Syst...