How to update items in custom listview content ?

Hi all,

I have a custom listview created. Now i want to update a contents of the listview based on a button Click. I got the contents to be update, but dont know how to proceed.

Can someone pls help me out here.?


Java file:

package com.example.firstandroid;


import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONObject;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class Screen2 extends ListActivity {

static String result="";
private static String DATA[];
private static String ADDR[];
* Demonstrates how to write an efficient list adapter. The adapter used in this example binds
* to an ImageView and to a TextView for each row in the list.
* To work efficiently the adapter implemented here uses two techniques:
* - It reuses the convertView passed to getView() to avoid inflating View when it is not necessary
* - It uses the ViewHolder pattern to avoid calling findViewById() when it is not necessary
* The ViewHolder pattern consists in storing a data structure in the tag of the view returned by
* getView(). This data structures contains references to the views we want to bind data to, thus
* avoiding calls to findViewById() every time getView() is invoked.

private static class EfficientAdapter extends BaseAdapter {
private LayoutInflater mInflater;
private Bitmap mIcon1;
private Bitmap mIcon2;

public EfficientAdapter(Context context) {
// Cache the LayoutInflate to avoid asking for a new one each time.
mInflater = LayoutInflater.from(context);

// Icons bound to the rows.
mIcon1 = BitmapFactory.decodeResource(context.getResources(), R.drawable.next_arrow);
mIcon2 = BitmapFactory.decodeResource(context.getResources(), R.drawable.next_arrow);

* The number of items in the list is determined by the number of speeches
* in our array.
* @see android.widget.ListAdapter#getCount()
public int getCount() {
return DATA.length+1;

* Since the data comes from an array, just returning the index is
* sufficent to get at the data. If we were using a more complex data
* structure, we would return whatever object represents one row in the
* list.
* @see android.widget.ListAdapter#getItem(int)
public Object getItem(int position) {
return position;

* Use the array index as a unique id.
* @see android.widget.ListAdapter#getItemId(int)
public long getItemId(int position) {
return position;

* Make a view to hold each row.
* @see android.widget.ListAdapter#getView(int, android.view.View,
* android.view.ViewGroup)
public View getView(int position, View convertView, ViewGroup parent) {
// A ViewHolder keeps references to children views to avoid unneccessary calls
// to findViewById() on each row.
ViewHolder holder;

// When convertView is not null, we can reuse it directly, there is no need
// to reinflate it. We only inflate a new View when the convertView supplied
// by ListView is null.

if(position == 0)
convertView = mInflater.inflate(R.layout.main1, null);
Button button = (Button)convertView.findViewById(;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.main2, null);

// Creates a ViewHolder and store references to the two children views
// we want to bind data to.
holder = new ViewHolder();
holder.title = (TextView) convertView.findViewById(;
holder.address = (TextView) convertView.findViewById(;
holder.icon = (ImageView) convertView.findViewById(;

} else {
// Get the ViewHolder back to get fast access to the TextView
// and the ImageView.
holder = (ViewHolder) convertView.getTag();

// Bind the data efficiently with the holder.
holder.icon.setImageBitmap((position & 1) == 1 ? mIcon1 : mIcon2);
return convertView;
static class ViewHolder {
TextView title;
TextView address;
ImageView icon;
private static OnClickListener mButtonListener = new OnClickListener() {
public void onClick(View v) {
// do something when the button is clicked

HttpClient client = new DefaultHttpClient();
String query = " hotel&start=0";
try {
URL url = new URL(query);
URI uri = new URI(url.getProtocol(), url.getHost(), url.getPath(), url.getQuery(), null);
HttpGet request = new HttpGet(uri);
HttpResponse response = client.execute(request);

}catch (URISyntaxException e){

catch(Exception ex){

public static String Userrequest(HttpResponse response){
String result = "";
InputStream in = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder str = new StringBuilder();
String line = null;
while((line = reader.readLine()) != null){
str.append(line + "\n");
result = str.toString();
// I have the data here, need to update the list. How to call Oncreate() function ?????
}catch(Exception ex){
result = "Error";
return result;

public void onCreate(Bundle savedInstanceState) {
Intent myIntent = new Intent(this , firstandroid.class);
//startActivityForResult(myIntent, 0);
Bundle bundle = getIntent().getExtras();
result = bundle.getString("mani");
JSONObject json=new JSONObject(result);
JSONArray ja;
json = json.getJSONObject("responseData");
ja = json.getJSONArray("results");

int resultCount = ja.length();
DATA = new String[resultCount];
ADDR = new String[resultCount];
for (int i = 0; i < resultCount; i++)
JSONObject resultObject = ja.getJSONObject(i);
// DATA[i]+="\n";
JSONArray addr;
addr = resultObject.getJSONArray("addressLines");
int count = addr.length();
for(int j=0;j


<?xml version="1.0" encoding="utf-8" ?>

can someone help me here?

- mani