views:

1024

answers:

2

Hello , I am using List View in my project where i have used a xml file which is used to create the list item.Then i have used it programmatically in my class which is extended by ListActivity. But the problem is i have to add a button in the bottom of screen which is not related to list view but List view covers all the screen. So,is there any way to add button in bottom with list view in android.

My Code is :-

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;

public class Options extends ListActivity {
    String[] items;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        requestWindowFeature(Window.FEATURE_RIGHT_ICON);

        items = getResources().getStringArray(R.array.chantOption_array);
        setListAdapter(new IconicAdapter());
        ListView lv = getListView();
        lv.setTextFilterEnabled(true);
        lv.setBackgroundResource(R.drawable.ichant_logo);
        setFeatureDrawableResource(Window.FEATURE_RIGHT_ICON, R.drawable.icon_t);


        lv.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                // When clicked, show a toast with the TextView text

                Toast.makeText(getApplicationContext(),
                        items[position], Toast.LENGTH_SHORT).show();


                if ("Gayatri Mantra".equals(items[position].toString())) {
                    int[] timeintervals = { 23900, 24000 };
                    // startChantActivity(TotalMala_loop,Total_Bead_Loop,BacgroundImage,Icon,Title,BeadsTotalTimeIntervals+totalTimeDurationOfAudio)
                    startChantActivity(2, 108, R.drawable.gayatri,
                            R.raw.gayatri, R.drawable.icon_gayatri,
                            "Gayatri Mantra", timeintervals);
                }
                if ("Om Mani Padme Hum".equals(items[position].toString())) {
                    int[] timeintervals = { 5500, 8200, 11100, 13900, 34100,
                            36700, 39500, 42300, 59300, 62000, 64800, 67600,
                            124600 };

                    // startChantActivity(TotalMala_loop,Total_Bead_Loop,BacgroundImage,Icon,Title,BeadsTotalTimeIntervals+totalTimeDurationOfAudio)

                    startChantActivity(2, 108, R.drawable.ommanipadmehum,
                            R.raw.om_mani, R.drawable.icon_padme,
                            "Om Mani Padme Hum", timeintervals);

                }
                if ("Sai Ram".equals(items[position].toString())) {

                    // Audio time interval for bead+total time duration of audio
                    int[] timeintervals = { 4800, 7500, 10400, 12600, 15800,
                            18600, 21600, 24400, 25000 };
                    // startChantActivity(TotalMala_loop,Total_Bead_Loop,BacgroundImage,Icon,Title,BeadsTotalTimeIntervals+totalTimeDurationOfAudio)
                    startChantActivity(2, 108, R.drawable.sairam, R.raw.sairam,
                            R.drawable.icon_sairam, "Sai Ram", timeintervals);
                }
                if ("Aum".equals(items[position].toString())) {
                    // Audio time interval for bead+total time duration of audio
                    int[] timeintervals = { 12850, 13000 };

                    // startChantActivity(TotalMala_loop,Total_Bead_Loop,BacgroundImage,Icon,Title,BeadsTotalTimeIntervals+totalTimeDurationOfAudio)

                    startChantActivity(2, 108, R.drawable.aum, R.raw.aum,
                            R.drawable.ico_aum, "Aum", timeintervals);
                }





            }
        });

    }



    class IconicAdapter extends ArrayAdapter {
        IconicAdapter() {
            super(Options.this, R.layout.list_item, items);

        }

        public View getView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = getLayoutInflater();
            View row = inflater.inflate(R.layout.list_item, parent, false);
            TextView label = (TextView) row.findViewById(R.id.label);
            label.setText(" "+items[position]);
            ImageView icon = (ImageView) row.findViewById(R.id.icon);
            if (items[position].equals("Gayatri Mantra")) {
                icon.setImageResource(R.drawable.icon_gayatri);
            }
            if (items[position].equals("Om Mani Padme Hum")) {
                icon.setImageResource(R.drawable.icon_padme);
            }
            if (items[position].equals("Sai Ram")) {
                icon.setImageResource(R.drawable.icon_sairam);
            }
            if (items[position].equals("Aum")) {
                icon.setImageResource(R.drawable.ico_aum);
            }
            return (row);
        }
    }


    protected void startChantActivity(int mala_loop, int beads_loop,
            int background, int media, int titleIcon, String title,
            int[] timeintervals) {

        Bundle bundle = new Bundle();
        bundle.putInt("mala_loop", mala_loop);
        bundle.putInt("beads_loop", beads_loop);
        bundle.putInt("background", background);
        bundle.putInt("media", media);
        bundle.putInt("titleIcon", titleIcon);
        bundle.putString("title", title);
        bundle.putIntArray("intervals", timeintervals);
        Intent intent = new Intent(this, ChantBliss.class);
        intent.putExtras(bundle);
        startActivityForResult(intent, this.getSelectedItemPosition());

    }
}

And Corresponding xml file is:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:paddingLeft="2px"
android:paddingRight="2px"
android:paddingTop="2px"
android:layout_height="wrap_content"

/>
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22sp"
android:textColor="#ff000000"

/>
</LinearLayout>

Thanks in Advance: Sandeep

A: 

Something like this did the trick for me:

<?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"
    >

<ListView android:id="@+id/list"
               android:layout_width="fill_parent" 
               android:layout_height="fill_parent"
               android:layout_weight="1"
               android:drawSelectorOnTop="false"/>

<LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        >
        <EditText
            android:id="@+id/newfilter"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:hint="Add a filter"

            />
        <Button
            android:id="@+id/addit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="fill_horizontal"
            android:drawableLeft="@drawable/btn_plus_pressed"
            />
    </LinearLayout>               
</LinearLayout>
LucaB
Thanks LucaB,I am using image also in my list view and that i have to create a coustomized Adapter class where i am passing the xml file.So,i think this is not helpful for me.Please look the code and if you have any solution then please help me.
Sandeep
Sorry but i didn't got the problem. My xml could also be passed to the Adapter.
LucaB
+1  A: 

android:gravity="bottom|right"

From: http://code.google.com/p/k9mail/source/browse/k9mail/trunk/res/layout/account_setup_basics.xml?r=1314

<RelativeLayout
        android:layout_marginTop="-45dip" 
        android:padding="0dip"
        android:layout_alignParentBottom="true"
        android:gravity="bottom|right" 
        android:background="@android:drawable/bottom_bar"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent">
        <Button
            android:id="@+id/manual_setup"
            android:text="@string/account_setup_basics_manual_setup_action"
            android:minWidth="@dimen/button_minWidth"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_marginBottom="-4dip" 
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="false" 
            />
        <Button
            android:id="@+id/next"
            android:text="@string/next_action"
            android:minWidth="@dimen/button_minWidth"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:drawableRight="@drawable/button_indicator_next"
            android:layout_marginBottom="-4dip" 
            android:layout_alignParentRight="true"
            android:layout_centerVertical="false" 
            />
    </RelativeLayout>

EDIT

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent">
<ListView ............... />
<!-- then my RelativeLayout -->
<RelativeLayout .............. />
</LinearLayout>
Pentium10
Thanks Pentium,I am using image also in my list view and that i have to create a coustomized Adapter class where i am passing the xml file.So,i think this is not helpful for me.Please look the code and if you have any solution then please help me.
Sandeep
This has nothing to do with `ListView` and or an `Adapter`. This goes into your XML view where you reference `@android:id/list`
Pentium10
I was having this problem as well. Didn't think about using margins to get around it. Thanks! (Wish there was a cleaner solution though)
hambonious