Thursday 19 January 2012

GETTING IMAGE FROM SERVER AND CONVERT INTO BITMAP

// GETTING IMAGE FROM SERVER AND CONVERT INTO BITMAP

public static Bitmap LoadImage(String URL) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 1;
       
        Bitmap bitmap = null;
        InputStream in = null;
        try {
            in = OpenHttpConnection(URL);
            bitmap = BitmapFactory.decodeStream(in, null, options);
            in.close();
        } catch (IOException e1) {
        }
        return bitmap;
    }

    public static InputStream OpenHttpConnection(String strURL) throws IOException {
        InputStream inputStream = null;
        URL url = new URL(strURL);
        URLConnection conn = url.openConnection();

        try {
            HttpURLConnection httpConn = (HttpURLConnection) conn;
            httpConn.setRequestMethod("GET");
            httpConn.connect();

            if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
                inputStream = httpConn.getInputStream();
            }
        } catch (Exception ex) {
        }
        return inputStream;
    }





/*
    Now call this in getView() method

        Bitmap bm = LoadImage(ib.getImage());
        holder.image.setImageBitmap(bm);
*/       

create Splash screen

create following two files in you project and in Manifest.xml make splasscreen as main activity

<activity android:name=".splashscreen">
   
    <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
    </activity> 

splash.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:background="@drawable/spl">
</RelativeLayout>

splashscreen.java


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;

public class splashscreen extends Activity{

    protected boolean _active = true;
    protected int _splashTime = 3000;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE); // No title displays
        setContentView(R.layout.splash);

        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            public void run() {
                finish();
               
                Intent i=new Intent(splashscreen.this,MainScreen.class);
                startActivity(i);
               
                            }
        }, _splashTime);
    }
   
}

To remove title in android

 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
      
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        
setContentView(R.layout.main);
-----------
}

SMS sent to caller when he CALLs you....

- no main.xml works in background so no application icon generated.
- give following permission in Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.PhoneCallSMS" android:versionCode="1" android:versionName="1.0">

    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
    <uses-permission android:name="android.permission.SEND_SMS"></uses-permission>

    <application android:icon="@drawable/icon" android:label="@string/app_name">
     
        <receiver android:name=".PhoneCallSMS">
            <intent-filter>
                <action android:name="android.intent.action.PHONE_STATE" />
            </intent-filter>
        </receiver>
       
    </application>
</manifest>

PhoneCallSMS.java

package com.PhoneCallSMS;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.telephony.gsm.SmsManager;
import android.util.Log;
import android.widget.Toast;

public class PhoneCallSMS extends BroadcastReceiver {
    //@SuppressWarnings("deprecation")
    @Override
    public void onReceive(Context context, Intent intent) {

        TelephonyManager telephony = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
       
        if(telephony.getCallState() == TelephonyManager.CALL_STATE_RINGING)
        {
       
        Bundle bundle = intent.getExtras();
        String phone_number = bundle.getString("incoming_number");

        String message = "Sorry, I am busy...will call you back..!";
       
        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phone_number, null, message, null, null);

        Log.e("Msg SENT", "SMS SENT TO RECEPIENT");

        Log.w("Incoming call", phone_number);
        Toast.makeText(context,
                "Hello,You have incoming call from..." + phone_number,
                Toast.LENGTH_LONG).show();
        }
    }
}

xml parsing using http Post method (displays query string)

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
       
    <TextView  android:id="@+id/tv_cityname" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
    <TextView  android:id="@+id/tv_latitude" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
    <TextView  android:id="@+id/tv_longitude" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
    <TextView  android:id="@+id/tv_currenttime" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
    <TextView  android:id="@+id/tv_sunrise" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
    <TextView  android:id="@+id/tv_sunset" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
    <TextView  android:id="@+id/tv_moonrise" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
    <TextView  android:id="@+id/tv_moonset" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
    <TextView  android:id="@+id/tv_unit" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
    <TextView  android:id="@+id/tv_value" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
    <TextView  android:id="@+id/tv_dist" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
   
    <Button android:text="Click to Parse" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
   
   
</LinearLayout>

Manifest.xml
Give internet permission...

WhetherTEMP.java

package com.WhetherTEMP;



import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

import com.WhetherTEMP.ClientMethod.RequestMethod;


import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class WhetherTEMP extends Activity {
    /** Called when the activity is first created. */
    TextView cityname,latitude,dirctn,currenttime,MetricSpeed,Stemp,Ctemp,LstUpdt,unit,value,dist;
    WhetherList loginsList = null;
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        cityname =(TextView)findViewById(R.id.tv_cityname);
        latitude=(TextView)findViewById(R.id.tv_latitude);
        dirctn=(TextView)findViewById(R.id.tv_longitude);
        currenttime=(TextView)findViewById(R.id.tv_currenttime);
        MetricSpeed=(TextView)findViewById(R.id.tv_sunrise);
        Stemp=(TextView)findViewById(R.id.tv_sunset);
        Ctemp=(TextView)findViewById(R.id.tv_moonrise);
        LstUpdt=(TextView)findViewById(R.id.tv_moonset);
        unit=(TextView)findViewById(R.id.tv_unit);
        value=(TextView)findViewById(R.id.tv_value);
        dist=(TextView)findViewById(R.id.tv_dist);
       
        Button ok=(Button)findViewById(R.id.button1);
       
        ok.setOnClickListener(new OnClickListener() {
           
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                checkLogin();
            }
        });
               
    }
   
   
private void checkLogin() {
       
        ClientMethod client = new ClientMethod("http://www.wunderground.com/cgi-bin/findweather/getForecast?brand=vitebXML&query=rajkot,india");

        try {
            client.Execute(RequestMethod.POST);
            InputSource inSource = client.getinpSource();

            SAXParserFactory spf = SAXParserFactory.newInstance();
            SAXParser sp = spf.newSAXParser();
            XMLReader xr = sp.getXMLReader();

            WhetherXMLHandler loginXMLhl = new WhetherXMLHandler();
            xr.setContentHandler(loginXMLhl);
            xr.parse(inSource);

            loginsList = loginXMLhl.getLoginsList();
            Message myMessage = new Message();
            myMessage.obj = "";
            handler2.sendMessage(myMessage);

        } catch (Exception e) {
            System.out.println("XML Pasing Excpetion = " + e);
        }
    }

    private Handler handler2 = new Handler() {
        @Override
        public void handleMessage(Message msg) {
           
            String lt = Double.toString(loginsList.getLati()); // CONVERT DOUBLE TO STRING
           
            cityname.setText("City name ::  " + loginsList.getCityName());
            latitude.setText("Latitude :: " + lt);
            currenttime.setText("Current time :: " + loginsList.getCurrenttime());
            LstUpdt.setText("Last Update time :: " + loginsList.getLstUpdttime());
            Ctemp.setText("Current temp Matric :: "+loginsList.getCtmpM());
            Stemp.setText("Current temp Std :: " + loginsList.getCtmpS());
            MetricSpeed.setText("Metric Speed :: " + loginsList.getSpeed());
            dirctn.setText("Metric Direction :: " + loginsList.getDir());
            unit.setText("Metric Unit :: " + loginsList.getUnit());
            value.setText("Metric Value :: " + loginsList.getVal());
            dist.setText("Metric Dist :: " + loginsList.getDist());
           
           
        }
    };
   
   
}



WhetherList.java

package com.WhetherTEMP;

public class WhetherList {

    private String cityname,currenttime,lastupdatedtime, ctmpM,ctmpS,speed,dir,unit,val,dst;
    private Double lati;
   



    public String getCityName() {
        return cityname;
    }

    public void setCityName(String cnm) {
        cityname = cnm;
    }
   
   
    public Double getLati() {
        return lati;
    }

    public void setLati(Double latit) {
        lati = latit;
    }

    public String getCurrenttime() {
        return currenttime;
    }

    public void setCurrenttime(String ctime) {
        currenttime = ctime;
    }
   
   
    public String getLstUpdttime() {
        return lastupdatedtime;
    }

    public void setLstUpdttime(String lstupdt) {
        lastupdatedtime = lstupdt;
    }
   
    public String getCtmpM() {
        return ctmpM;
    }

    public void setCtmpM(String ctm) {
        ctmpM = ctm;
    }

    public String getCtmpS() {
        return ctmpS;
    }

    public void setCtmpS(String cts) {
        ctmpS = cts;
    }

   
    public String getSpeed() {
        return speed;
    }

    public void setSpeed(String spd) {
        speed = spd;
    }
   
    public String getDir() {
        return dir;
    }

    public void setDir(String dir1) {
        dir = dir1;
    }
   
   
    public String getUnit() {
        return unit;
    }

    public void setUnit(String u) {
        unit = u;
    }

   
    public String getVal() {
        return val;
    }
    public void setVal(String value) {
        // TODO Auto-generated method stub
        val = value;
    }


    public String getDist() {
        return dst;
    }
    public void setDist(String dist) {
        // TODO Auto-generated method stub
        dst = dist;
    }
   

}


WhetherXMLHandler.java

package com.WhetherTEMP;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class WhetherXMLHandler extends DefaultHandler {
    private StringBuffer buffer = new StringBuffer();
    public static WhetherList loginsList = null;

    String currentValue = null;

    public static WhetherList getLoginsList() {
        return loginsList;
    }

    public static void setLoginsList(WhetherList loginsList) {
        WhetherXMLHandler.loginsList = loginsList;
    }

    @Override
    public void startElement(String uri, String localName, String qName,
            Attributes attributes) throws SAXException {

        buffer.setLength(0);

        if (localName.equals("weather")) {

            if (loginsList == null) {
                loginsList = new WhetherList();
            }
        }

        else if (localName.equals("currenttemp")) {
            String metric1 = attributes.getValue("metric");
            loginsList.setCtmpM(metric1);

            String standard1 = attributes.getValue("standard");
            loginsList.setCtmpS(standard1);
        }
           
        else if(localName.equals("metric"))
            {
                String speed = attributes.getValue("speed");
                loginsList.setSpeed(speed);
       
                String dirct= attributes.getValue("direction");
                loginsList.setDir(dirct);
               
                String unt= attributes.getValue("unit");
                loginsList.setUnit(unt);
               
                String value= attributes.getValue("val");
                loginsList.setVal(value);
               
                String dist= attributes.getValue("dist");
                loginsList.setDist(dist);
           
            }
           
           
        }


    @Override
    public void endElement(String uri, String localName, String qName)
            throws SAXException {

        if (localName.equalsIgnoreCase("cityname"))
            loginsList.setCityName(buffer.toString());

        else if (localName.equalsIgnoreCase("latitude"))

            loginsList.setLati(Double.valueOf(buffer.toString()));

        else if (localName.equalsIgnoreCase("currenttime"))
            loginsList.setCurrenttime(buffer.toString());

        else if (localName.equalsIgnoreCase("lastupdatedtime"))
            loginsList.setLstUpdttime(buffer.toString());

    }

    @Override
    public void characters(char[] ch, int start, int length)
            throws SAXException {

        buffer.append(ch, start, length);
    }

}


ClientMethod.java

package com.WhetherTEMP;

import java.net.URLEncoder;
import java.util.ArrayList;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.xml.sax.InputSource;

public class ClientMethod {
   
    public enum RequestMethod {
        GET, POST
    }

    private String url;
    private ArrayList<NameValuePair> params;
    private HttpEntity respEntity;
    private InputSource inpSource;

    public HttpEntity getrespEntity() {
        return respEntity;
    }

    public InputSource getinpSource() {
        return inpSource;
    }

    public void AddParam(String name, String value) {
        params.add(new BasicNameValuePair(name, value));
    }

    public ClientMethod(String url) {
        this.url = url;
        params = new ArrayList<NameValuePair>();
    }

    public void Execute(RequestMethod method) throws Exception {
        switch (method) {
        case GET: {
            // add parameters
            String combinedParams = "";
            if (!params.isEmpty()) {
                combinedParams += "?";
                for (NameValuePair p : params) {
                    String paramString = p.getName() + "="
                            + URLEncoder.encode(p.getValue(), "UTF-8");
                    if (combinedParams.length() > 1) {
                        combinedParams += "&" + paramString;
                    } else {
                        combinedParams += paramString;
                    }
                }
            }

            HttpGet request = new HttpGet(url + combinedParams);

            executeRequest(request, url);
            break;
        }
        case POST: {
            HttpPost request = new HttpPost(url);

            if (!params.isEmpty()) {
                request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
            }

            executeRequest(request, url);
        }
        }
    }

    private void executeRequest(HttpUriRequest request, String url) {
        HttpClient client = new DefaultHttpClient();
        HttpResponse httpResponse;
        try {
            httpResponse = client.execute(request);
            respEntity = httpResponse.getEntity();
            inpSource = retrieveInputStream(respEntity);

//            SAXParserFactory spf = SAXParserFactory.newInstance();
//            SAXParser sp = spf.newSAXParser();
//            XMLReader xr = sp.getXMLReader();
//            MyXMLHandler myXMLHandler = new MyXMLHandler();
//            xr.setContentHandler(myXMLHandler);
//            xr.parse(inpSource);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private InputSource retrieveInputStream(HttpEntity httpEntity) {
        InputSource insrc = null;
        try {
            insrc = new InputSource(httpEntity.getContent());
        } catch (Exception e) {
        }
        return insrc;
    }



}

integrate fb in app

To integrate facebook...
http://www.techrepublic.com/blog/app-builder/integrate-facebook-logins-in-your-android-app/296

another link...

http://android10.org/index.php/articleslibraries/290-facebook-integration-in-your-android-applicatio

links android

***********send data using post method in android **************
http://nscraps.com/Android/794-sending-data-post-method-android.htm
************************************************************************

****************

http://androidsamples.blogspot.com/2009/06/how-to-use-http-connection-saxparser.html
http://www.happygeek.in/pages/list-of-contents

http://developer.android.com/resources/tutorials/views/hello-tabwidget.html
http://androiddevcentral.com/source-code/

*****************Bottom tab bar********************
http://androidworkz.com/2011/02/04/custom-menu-bar-tabs-how-to-hook-the-menu-button-to-showhide-a-custom-tab-bar/
*************************************************************************

********************how to store username password in device memory*****************
http://stackoverflow.com/questions/3063108/how-to-store-username-password-in-device-memory
***********************************************************************
http://stackoverflow.com/questions/6271706/shared-preferences-doesnt-seem-to-save-username-in-session
http://kpbird.blogspot.com/2011/05/androidbottom-tabbar-control.html#more
http://en.wikipedia.org/wiki/List_of_open_source_Android_applications
http://pareshnmayani.wordpress.com/category/android/useful-utility/
http://geekswithblogs.net/bosuch/archive/2011/01/31/android---create-a-custom-multi-line-listview-bound-to-an.aspx
http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/
http://saigeethamn.blogspot.com/2010/04/custom-listview-android-developer.html
http://www.techrepublic.com/blog/app-builder/integrate-facebook-logins-in-your-android-app/296
http://android10.org/index.php/articleslibraries/290-facebook-integration-in-your-android-applicatio
http://android10.org/index.php/articleslibraries/291-twitter-integration-in-your-android-application
http://abhinavasblog.blogspot.com/2010/09/using-twitter-with-oauth-on-andorid.html
http://i2.grepcode.com/snapshot/repo1.maven.org/maven2/oauth.signpost/signpost-commonshttp4/1.2.1.1
http://blog.doityourselfandroid.com/2011/08/08/improved-twitter-oauth-android/


**********Ready made alert box with code*******
http://www.monmonja.com/android/alert
************************************

*****fo Arabic characters****
http://mdictionary.wordpress.com/2011/02/10/connected-arabic-characters-for-android-apps/
********************************

***********Never ending list************
http://p-xr.com/android-tutorial-dynamicaly-load-more-items-to-the-listview-never-ending-list/
******************************

***********Multi collumn list view**********
http://www.heikkitoivonen.net/blog/2009/02/15/multicolumn-listview-in-android/
**************************************

**********You tube source code**********
http://tutorials-android.blogspot.com/2011/07/you-tube-source-code.html
**************************************

*************Android most of project source code*************
http://www.java2s.com/Open-Source/Android/CatalogAndroid.htm
****************************************



Parsing using Http get method...

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
   
    <LinearLayout android:layout_width="match_parent"
        android:layout_height="wrap_content" android:id="@+id/linearLayout1"></LinearLayout>
    <TextView android:id="@+id/tv_title" android:layout_width="wrap_content"
        android:layout_height="wrap_content"></TextView>
    <TextView android:id="@+id/tv_actId" android:layout_width="wrap_content"
        android:layout_height="wrap_content"></TextView>
    <TextView android:id="@+id/tv_loc" android:layout_width="wrap_content"
        android:layout_height="wrap_content"></TextView>
   
   
    <ListView android:layout_height="wrap_content" android:id="@+id/lv_activitylist"
        android:layout_width="match_parent"></ListView>

</LinearLayout>

 
Manifest.xml

Give Internet permission only


ActivityFirst.java

package com.ParsingData;

import java.util.ArrayList;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

import android.R.layout;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ParsingData.ClientMethod.RequestMethod;

public class ActivityFirst extends Activity {
    /** Called when the activity is first created. */

    TextView activityId, location, title;

    ArrayList<ActivityList> arrayItems;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        activityId = (TextView) findViewById(R.id.tv_actId);
        location = (TextView) findViewById(R.id.tv_loc);
        title = (TextView) findViewById(R.id.tv_title);

        ParseData();

    }

    public void ParseData() {

        SharedPreferences user = getSharedPreferences("SELECTED_LOCATION_PREF",
                MODE_PRIVATE);
        String locationID = "cz";// user.getString("locationid", "");

        ClientMethod client = new ClientMethod(
                "http://www.e-traveldirect.com/wsmobile/WsMobile.asmx/GetActivities");
          
            // Visit site for ref.
            // http://www.e-traveldirect.com/wsmobile/WsMobile.asmx?op=GetActivities
           
        client.AddParam("location", locationID);

        try {
            client.Execute(RequestMethod.POST);
            InputSource inSource = client.getinpSource();

            SAXParserFactory spf = SAXParserFactory.newInstance();
            SAXParser sp = spf.newSAXParser();
            XMLReader xr = sp.getXMLReader();

            ActivityXMLhandler campusXMLhl = new ActivityXMLhandler();
            xr.setContentHandler(campusXMLhl);
            xr.parse(inSource);

            arrayItems = ActivityXMLhandler.getArrayData();

            Message myMessage = new Message();
            myMessage.obj = "";
            handler2.sendMessage(myMessage);

        } catch (Exception e) {
            System.out.println("XML Pasing Excpetion = " + e);
        }
    }

    private Handler handler2 = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout1);
            for (int t = 0; t < arrayItems.size(); t++) {

                /*
                 * activityId.setText("Activity ID ::  " +
                 * arrayItems.get(0).getActId());
                 * location.setText("Location :: " +
                 * arrayItems.get(0).getLoc()); title.setText("Title :: " +
                 * arrayItems.get(0).getTitle());
                 */

                TextView textView = new TextView(ActivityFirst .this);
                TextView textView1 = new TextView(ActivityFirst .this);
                textView.setText("Activity ID ::" +"\n"
                        + arrayItems.get(t).getActId());
               
                LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
                        LinearLayout.LayoutParams.WRAP_CONTENT,
                        LinearLayout.LayoutParams.WRAP_CONTENT,
                        LinearLayout.VERTICAL);
                textView1.setText("\n");
                layout.addView(textView, p);
               
               
            }

            /*
             * activityId.setText("Activity ID ::  " + ActList.getActId());
             * location.setText("Location :: " + ActList.getLoc());
             * title.setText("Title :: " + ActList.getTitle());
             */
        }
    };

}


ActivityList.java

package com.ParsingData;

import java.util.ArrayList;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class ActivityList extends BaseAdapter{

   
    private String actId, loc, title;
   
   
    public ActivityList(ActivityFirst activityFirst,
            ArrayList<ActivityList> arrayItems) {
        // TODO Auto-generated constructor stub
    }
    public ActivityList() {
        // TODO Auto-generated constructor stub
    }
    public String getActId() {
        return actId;
    }
    public void setActId(String actId) {
        this.actId = actId;
    }
    public String getLoc() {
        return loc;
    }
    public void setLoc(String loc) {
        this.loc = loc;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return 0;
    }
    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return null;
    }
    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        return null;
    }

}


ActivityXMLhandler.java

package com.ParsingData;
import java.util.ArrayList;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class ActivityXMLhandler extends DefaultHandler {
    private StringBuffer buffer = new StringBuffer();
    public static ArrayList<ActivityList> arrayData;
    private ActivityList data;

   
    public static ArrayList<ActivityList> getArrayData() {
        return arrayData;
    }

    public static void setArrayData(ArrayList<ActivityList> arrayData) {
        ActivityXMLhandler.arrayData = arrayData;
    }

    @Override
    public void startElement(String uri, String localName, String qName,
            Attributes attributes) throws SAXException {

        buffer.setLength(0);

        if (localName.equals("activities")) {
            arrayData = new ArrayList<ActivityList>();
        } else if (localName.equals("activity")) {
            data = new ActivityList();
        }

    }

    @Override
    public void endElement(String uri, String localName, String qName)
            throws SAXException {
        if (localName.equalsIgnoreCase("activityid"))
            data.setActId(buffer.toString());
        else if (localName.equalsIgnoreCase("location"))
            data.setLoc(buffer.toString());
        else if (localName.equalsIgnoreCase("title"))
            data.setTitle(buffer.toString());
        else if (localName.equalsIgnoreCase("activity"))
            arrayData.add(data);
    }

    @Override
    public void characters(char[] ch, int start, int length)
            throws SAXException {
        buffer.append(ch, start, length);
    }

}


ClientMethod.java

package com.ParsingData;


import java.net.URLEncoder;
import java.util.ArrayList;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.xml.sax.InputSource;

public class ClientMethod {

    public enum RequestMethod {
        GET, POST
    }

    private String url;
    private ArrayList<NameValuePair> params;
    private HttpEntity respEntity;
    private InputSource inpSource;

    public HttpEntity getrespEntity() {
        return respEntity;
    }

    public InputSource getinpSource() {
        return inpSource;
    }

    public void AddParam(String name, String value) {
        params.add(new BasicNameValuePair(name, value));
    }

    public ClientMethod(String url) {
        this.url = url;
        params = new ArrayList<NameValuePair>();
    }

    public void Execute(RequestMethod method) throws Exception {
        switch (method) {
        case GET: {
            // add parameters
            String combinedParams = "";
            if (!params.isEmpty()) {
                combinedParams += "?";
                for (NameValuePair p : params) {
                    String paramString = p.getName() + "="
                            + URLEncoder.encode(p.getValue(), "UTF-8");
                    if (combinedParams.length() > 1) {
                        combinedParams += "&" + paramString;
                    } else {
                        combinedParams += paramString;
                    }
                }
            }

            HttpGet request = new HttpGet(url + combinedParams);

            executeRequest(request, url);
            break;
        }
        case POST: {
            HttpPost request = new HttpPost(url);

            if (!params.isEmpty()) {
                request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
            }

            executeRequest(request, url);
        }
        }
    }

    private void executeRequest(HttpUriRequest request, String url) {
        HttpClient client = new DefaultHttpClient();
        HttpResponse httpResponse;
        try {
            httpResponse = client.execute(request);
            respEntity = httpResponse.getEntity();
            inpSource = retrieveInputStream(respEntity);
           
            // Only Print XML
            //InputStream aa = respEntity.getContent();
            //StringBuilder bb = inputStreamToString(aa);
            //Log.i("Response", bb.toString());
            // Only Print XML

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

//    private StringBuilder inputStreamToString(InputStream is) {
//        String line = "";
//        StringBuilder total = new StringBuilder();
//
//        // Wrap a BufferedReader around the InputStream
//        BufferedReader rd = new BufferedReader(new InputStreamReader(is));
//
//        // Read response until the end
//        try {
//            while ((line = rd.readLine()) != null) {
//                total.append(line);
//            }
//        } catch (IOException e) {
//            // TODO Auto-generated catch block
//            e.printStackTrace();
//        }
//
//        // Return full string
//        return total;
//    }

    private InputSource retrieveInputStream(HttpEntity httpEntity) {
        InputSource insrc = null;
        try {
            insrc = new InputSource(httpEntity.getContent());
        } catch (Exception e) {
        }
        return insrc;
    }
   
}