Set List View Size Android

Posted by Sandeep on Stack Overflow See other posts from Stack Overflow or by Sandeep
Published on 2010-03-19T13:32:06Z Indexed on 2010/03/19 13:51 UTC
Read the original article Hit count: 1017

Filed under:
|
|
|

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

© Stack Overflow or respective owner

Related posts about listview

Related posts about size