ArrayAdapter is repeating UI Header for every item in ListView
===

I am facing an issue in showing a list of items in the UI.

My UI layout page layout:

"

        <?xml version="1.0" encoding="utf-8"?>
        
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/ListOfRecordsContainer"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#454545"
            android:orientation="vertical" >
        <include
            android:layout_weight="1"
            layout="@layout/header" />
    
    <TextView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/ListOfRecords"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="0.01"
        android:padding="1dp"
        android:textSize="12sp" >
    </TextView>
    
    </LinearLayout>

"


In the Class, onSuccess method is called once the list is retrieved from a remote system and populate the TextView in the UI.

But,the Header part included in the layout is getting repeated for every record. Am I missing anything here??

For instance....Actual result is

    <Header Button for LogOut>
    Item1
    <Header Button for LogOut>
    Item2

Expected Result is 

    <Header Button for LogOut>
    Item1
    Item2


Code is shown below:

====================================================================================

        package com.demo.crmandroidapp;
    
    import org.json.JSONArray;
    import org.json.JSONObject;
    
    import android.app.ListActivity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.view.ViewGroup;
    import android.view.ViewGroup.LayoutParams;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemClickListener;
    import android.widget.ArrayAdapter;
    import android.widget.Button;
    import android.widget.LinearLayout;
    import android.widget.ListView;
    import android.widget.TextView;
    import android.widget.Toast;
    
    import com.salesforce.androidsdk.app.ForceApp;
    import com.salesforce.androidsdk.rest.ClientManager;
    import com.salesforce.androidsdk.rest.ClientManager.LoginOptions;
    import com.salesforce.androidsdk.rest.ClientManager.RestClientCallback;
    import com.salesforce.androidsdk.rest.RestClient.AsyncRequestCallback;
    import com.salesforce.androidsdk.rest.RestClient;
    import com.salesforce.androidsdk.rest.RestRequest;
    import com.salesforce.androidsdk.rest.RestResponse;
    import com.salesforce.androidsdk.util.EventsObservable;
    import com.salesforce.androidsdk.util.EventsObservable.EventType;
    
    public class ItemMainPage extends ListActivity{
    
        private String[] AccountName;
        private String[] AccountIds;
        private RestClient client;
        private String apiVersion;
    
        LinearLayout layout;
        
    	public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            
            ListView lv = getListView();
            apiVersion = getString(R.string.api_version);
            
    		lv.setTextFilterEnabled(true);
    
    	    /*layout = (LinearLayout) View.inflate(this, R.layout.list_item_main_page, null);
    		Button buyButton = new Button(this);
    	    buyButton.setText("Search");
    	    layout.addView(buyButton);*/
    		
    		
    	}
     
    	@Override
    	public void onResume(){
    		super.onResume();
    		
    		// Login options
    		String accountType = getString(R.string.account_type);
    		LoginOptions loginOptions = new LoginOptions(
    				null, // gets overridden by LoginActivity based on server picked by uuser 
    				ForceApp.APP.getPasscodeHash(),
    				getString(R.string.oauth_callback_url),
    				getString(R.string.oauth_client_id),
    				new String[] {"api"});
    		
    		new ClientManager(this, accountType, loginOptions).getRestClient(this, new RestClientCallback() {
    			//@Override
    			public void authenticatedRestClient(RestClient client) {
    				if (client == null) {
    					ForceApp.APP.logout(ItemMainPage.this);
    					return;
    				}
    				ItemMainPage.this.client = client;
    				getAccountList();
    			}
    		});
    		EventsObservable.get().notifyEvent(EventType.RenditionComplete);
    	}	
    
    	private void getAccountList(){
    
    		try {
    			
    			String soql = "select id, name from Account LIMIT 2";
    			RestRequest request = RestRequest.getRequestForQuery(apiVersion, soql);
    
    			client.sendAsync(request, new AsyncRequestCallback() {
    
    				//@Override
    				public void onSuccess(RestRequest request, RestResponse response) {
    					try {
    						if (response == null || response.asJSONObject() == null)
    							return;
    						
    						JSONArray records = response.asJSONObject().getJSONArray("records");
    	
    						if (records.length() == 0)
    							return;
    										
    				    	AccountName = new String[records.length()];
    				    	AccountIds = new String[records.length()];
    						
    						for (int i = 0; i < records.length(); i++){
    							JSONObject Account = (JSONObject)records.get(i);
    							AccountName[i] = Account.getString("Name");
    							AccountIds[i] = Account.getString("Id");
    						}
    				        //ArrayAdapter<String> ad = new ArrayAdapter<String>(ItemMainPage.this, 
    				        //												   R.layout.list_item_main_page, 
    				        //												   AccountName);
    				        ArrayAdapter<String> ad = new ArrayAdapter<String>(ItemMainPage.this, R.layout.list_item_main_page, R.id.ListOfRecords, AccountName); 
    				        setListAdapter(ad);
    				        Log.d("Adapter", ad.toString());
    				        //EventsObservable.get().notifyEvent(EventType.RenditionComplete);
    					} catch (Exception e) {
    						e.printStackTrace();
    						displayError(e.getMessage());
    					}
    				}
    				
    				//@Override
    				public void onError(Exception exception) {
    					displayError(exception.getMessage());
    					EventsObservable.get().notifyEvent(EventType.RenditionComplete);
    				}
    			});
    			
    		} catch (Exception e) {
    			e.printStackTrace();
    			displayError(e.getMessage());
    		}
    	}
    
    	
    	private void displayError(String error)	{
            //ArrayAdapter<String> ad = new ArrayAdapter<String>(	AccountList.this, R.layout.list_item, new String[]{"Error retrieving Account data - " + error});
            //setListAdapter(ad);
          ((TextView) findViewById(R.id.welcome_text)).setText(getString(R.string.welcome, client.getClientInfo().username));
    		
    	}
    
    }

====================================================================================

Please help if I am missing anything

Thanks and Regards,
Ravi


  [1]: http://i.stack.imgur.com/7ZXAm.jpg
