I have a list view witch is instantiated through the XML document
what i would like to do is add a single button at the top of the
list.....I've accomplished this by adding a coded button to oncreate
and using addheaerview to add it to the top of the list the problem is
the button extends the full length of the list view i only want say a
100x25px button but i have no idea how to add this either in the XML
document or with java code.Plz help here is the javacode and xml.



[code]
<?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="wrap_content">
<!-- A three column list view layout requires the center column to be
defined first in the XML document Hierarchy -->


<TextView
        android:id="@+id/TextView1"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:textColor="#000000"
        android:layout_centerHorizontal="true"
        android:text="android"
        />
<TextView
        android:id="@+id/TextView0"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_toLeftOf="@+id/TextView1"
        android:layout_below="@+id/GetData_btn"
        android:text="android"
        android:textColor="#000000"
        />
<TextView
        android:id="@+id/TextView2"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_toRightOf="@+id/TextView1"
        android:layout_marginRight="25dip"
        android:textColor="#000000"
        android:gravity="right"
        android:text="android"
        />
<ListView android:id="@+id/ListView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></ListView>

</RelativeLayout>


[/code]








[code]
package com.cuslistview;
import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
public class customlistview extends Activity implements
OnClickListener{
        ListView l1;
         private static class EfficientAdapter extends BaseAdapter {
        private LayoutInflater mInflater;
        private ArrayList<ArrayList<String>> ret=null;

         public EfficientAdapter(Context context) {
                  Sax sax1 = new Sax();
                  try {
                        ret =  sax1.SaxIni();
                } catch (Exception e) {

                        e.printStackTrace();
                }


                   mInflater = LayoutInflater.from(context);



                  }

                @Override
                public int getCount() {

                        return ret.size();
                }

                @Override
                public Object getItem(int position) {

                        return position;
                }

                @Override
                public long getItemId(int position) {

                        return position;
                }

                @Override
                public View getView(int position, View convertview, ViewGroup
parent) {


                        ViewHolder holder;
                          if (convertview == null) {

                          convertview = mInflater.inflate(R.layout.main, 
parent,false);

                          holder = new ViewHolder();

                          //holder.text = (TextView)
convertview.findViewById(R.id.TextView01);

                          holder.text0 = (TextView)
convertview.findViewById(R.id.TextView0);
                          holder.text1 = (TextView)
convertview.findViewById(R.id.TextView1);
                          holder.text2 = (TextView)
convertview.findViewById(R.id.TextView2);


                          convertview.setTag(holder);

                          } else {

                          holder = (ViewHolder) convertview.getTag();

                  }



                          //holder.text.setText(ret.get(position));
                          holder.text0.setText(ret.get(0).get(position));
                          holder.text1.setText(ret.get(1).get(position));
                          holder.text2.setText(ret.get(2).get(position));
                          //convertview.setBackgroundColor((position & 1) == 1 ?
Color.WHITE : Color.LTGRAY);
                          convertview.setBackgroundColor((position & 1) == 1 ?
Color.LTGRAY : Color.GREEN);

                          return convertview;

                          }



                          static class ViewHolder {

                          TextView text0;
              TextView text1;
              TextView text2;

                          }

                          }



                          @Override

                          public void onCreate(Bundle savedInstanceState) {
                                  Button getdata_btn;
                                  //LinearLayout layout1;

                                  super.onCreate(savedInstanceState);

                          setContentView(R.layout.main);
                         // layout1 = new LinearLayout(this);
                         // layout1.setOrientation(LinearLayout.HORIZONTAL);
                         //  layout1.setGravity(Gravity.CENTER);
                          // setContentView(layout1);

                          getdata_btn = new Button(this);
                          getdata_btn.setWidth(5);
              getdata_btn.setHeight(5);
                          getdata_btn.setText("Update");
              getdata_btn.setOnClickListener(this);

              l1 = (ListView) findViewById(R.id.ListView01);
                          ColorDrawable divcolor  = new 
ColorDrawable(Color.RED);
                  l1.addHeaderView(getdata_btn);

                          l1.setDivider(divcolor);

                          l1.setDividerHeight(2);
                  //layout1.addView(getdata_btn);

                          l1.setAdapter(new EfficientAdapter(this));

                          }



                        @Override
                        public void onClick(View v) {
                                  l1.setAdapter(new EfficientAdapter(this));

                        }







         }


[/code]

-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to