Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8276011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:15:11+00:00 2026-06-08T08:15:11+00:00

how to display the listview value. I have one dropdown spinner.if i selected the

  • 0

how to display the listview value. I have one dropdown spinner.if i selected the spinner item, the specified list item value will be displayed in the custom listview.

//SampActivity.java

 class GlobalClass extends Application {
 public static List<String> myval=new ArrayList<String>();

  }
      public  class SampActivity extends Activity {
                 String[] Category={"----SELECT---- ",        "BEVERAGES","BREAKFAST","LUNCH","DINNER","DESSERTS","APPETIZERS & SIDES"};

  Spinner spinner;
   ListView l1;


   String[] item;
   int myid;
 /** Called when the activity is first created. **/
 @Override
 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    spinner = (Spinner) findViewById(R.id.spinnerCategory);
    l1.setAdapter(new EfficientAdapter(this));
    l1=(ListView) findViewById (R.id.list);
    b1=(Button)findViewById(R.id.button3);
    b2=(Button)findViewById(R.id.button2);
    b3=(Button)findViewById(R.id.button1);
    e1=(EditText)findViewById(R.id.editText1);
    e2=(EditText)findViewById(R.id.editText2);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, Category);
   adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);


    spinner.setOnItemSelectedListener(new OnItemSelectedListener(){

    public void onItemSelected(AdapterView<?> parent, View arg1, int pos,long id) {              


  String Text = parent.getSelectedItem().toString();
    if(Text.equals("----SELECT----")) {

    }       
    else if(Text.equals("BEVERAGES")){

       l1.setAdapter(bever);

       return;
   }    
   else if(Text.equals("BREAKFAST")){

       l1.setAdapter(Breakf);
       return;
   }
   else if(Text.equals("LUNCH")){

       l1.setAdapter(lunc);
       return;
   }
   else if(Text.equals("DINNER")){
       l1.setAdapter(Dinn);
       return;

   }
   else if(Text.equals("DESSERTS")){
       l1.setAdapter(Dessert);
       return;

   }
   else if(Text.equals("APPETIZERS & SIDES")){
       l1.setAdapter(Appet);
       return;

   }
     }


     public void onNothingSelected(AdapterView<?> arg0){

              }

        });

   l1.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(), "SELECTED :: " +((TextView) view).getText(),
        Toast.LENGTH_SHORT).show();


     String st1 =(String) parent.getItemAtPosition(position); 
        GlobalClass.myval.add(st1);


       }
   });



}
private static class EfficientAdapter extends BaseAdapter {
    private LayoutInflater mInflater;
    public EfficientAdapter(Context context) {
        mInflater = LayoutInflater.from(context);
    }

    public int getCount() {
        return StrActivity.Beverage.length;

    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

     public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.listview_row, null);
            holder = new ViewHolder();
            holder.text1 = (TextView) convertView
                    .findViewById(R.id.TextView01);
            holder.text2 = (TextView) convertView
                    .findViewById(R.id.TextView02);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.text1.setText(StrActivity.Beverage[position]);
        holder.text2.setText(StrActivity.Beveragecos[position]);
        return convertView;
      }
     static class ViewHolder {
        TextView text1;
        TextView text2;
    }
}
 }

//StrActivity.java

 package com.tru.samp;

  public class StrActivity {
    public static String[] Beverage={"PEPSI","COKE","LASSI","FALOODA","BUTTER MILK","GREEN TEA","BADAM MILK","MASALA CHAI" };
     public static String[] Beveragecos={"$ 0.5","$ 0.5","$ 2.0","$ 3.0","$ 1.5","$ 0.7","$ 0.8","$ 1.0"};
    public static String[] Breakfast={"SIRLOIN & EGG","CFS STEAK & EGG","T-BONE & EGG","TWO EGGS BREAKFAST","2EGG W/MEAT","BEL WAFFLE","BEL WAFFLE W/MEAT","BLUEBERRY CAKE","CAKES","FABULOUS FRENCH TST","MOONS","FRENCH TST"};
     public static String[] Breakfastcos={"$ 2.5","$ 3.0","$ 3.5","$ 2.7","$ 4.7","$ 3.0","$ 5.6","$ 3.0","$ 2.5","$ 3.2","$ 2.0","$ 1.0"};
     public static String[] Lunch={" CRAB CAKE SANDWICH","TUSCAN GRILLED CHICKEN PANINI","SOUTHWEST TURKEY CLUB"," LOBSTER ROLL","TUNA MELT"," FRENCH DIP","YOUR OWN SANDWICH"};
     public static String[] Lunchcos={"$ 4.0","$ 4.5","$ 7.0","$ 3.5","$ 5.5","$ 6.3","$ 5.0"};
     public static String[] Dinner={"DUBLIN BAY PRAWN","CRAB FROM BRITTANY","WHITE ASPARAGUS","BLEWIT MUSHROOM","JOHN DORY FISH","MONKFISH","VEAL SWEET BREAD","LAMB","PIGEON FRY"};
     public static String[] Dinnercos={"$ 3.5","$ 4.5","$ 3.3","$ 2.6","$ 4.3","$ 3.7","$ 2.5","$ 3.0","$ 4.0"};
     public static String[] Desserts={"ECHOURGNAC CHEESE","HAZELNUT","GARIGUETTE STRAWBERRY","MOUSSE & ZEST","APRICOT","CHOCOLATE"};
      public static String[] Dessertscos={"$ 1.0","$ 1.5","$ 2.7","$ 4.0","$ 2.9","$ 1.5"};
     public static String[] Appetizers={"Greek Artichoke Spinach","Seafood Appetizers","Tapenade Flatbread","Cranberry Blue Cheese","Fig and Blue Cheese","Sun-Dried Tomato","Tropical Crab Rangoon"};
     public static String[] Appertizerscos={"$ 1.3","$ 2.7","$ 1.5","$ 2.0","$ 2.5","$ 2.3","$ 3.0"};
}

thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T08:15:14+00:00Added an answer on June 8, 2026 at 8:15 am

    Check out this:

        listView=(ListView) findViewById(R.id.list);
        spinner=(Spinner) findViewById(R.id.spin);
        ArrayAdapter<String> adapter=new ArrayAdapter<String>(HotelActivity.this, android.R.layout.simple_spinner_item,Category);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);
        spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
    
            public void onItemSelected(AdapterView<?> parent, View arg1,
                    int pos, long arg3) {
                String Text = parent.getSelectedItem().toString();
                if(Text.equals("----SELECT----")) {
    
                }       
                else if(Text.equals("BEVERAGES")){
                    CustomAdapter bever=new CustomAdapter(HotelActivity.this,pos,Beverage.length);
                    listView.setAdapter(bever);
                   return;
               }    
               else if(Text.equals("BREAKFAST")){
                   CustomAdapter breakfast=new CustomAdapter(HotelActivity.this,pos,Breakfast.length);
                   listView.setAdapter(breakfast);
                   return;
               }
               else if(Text.equals("LUNCH")){
                   CustomAdapter lunch=new CustomAdapter(HotelActivity.this,pos,Lunch.length);
                    listView.setAdapter(lunch);
                   return;
               }
               else if(Text.equals("DINNER")){
                   CustomAdapter dinner=new CustomAdapter(HotelActivity.this,pos,Dinner.length);
                   listView.setAdapter(dinner);
                   return;
    
               }
               else if(Text.equals("DESSERTS")){
                   CustomAdapter dessert=new CustomAdapter(HotelActivity.this,pos,Desserts.length);
                    listView.setAdapter(dessert);
                   return;
    
               }
               else if(Text.equals("APPETIZERS & SIDES")){
                   CustomAdapter app=new CustomAdapter(HotelActivity.this,pos,Appetizers.length);
                    listView.setAdapter(app);
                   return;
    
               }
            }
    
            public void onNothingSelected(AdapterView<?> arg0) {
    
            }
        });
    

    main.xml

    <?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="fill_parent"
        android:orientation="vertical" >
    
        <TextView
            android:id="@+id/txt"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/hello" 
            />
    
    
        <Spinner 
            android:id="@+id/spin"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/> 
    
            <ListView 
                android:id="@+id/list"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"/>
    
    </LinearLayout>
    

    CustomAdapter Class:

    public class CustomAdapter extends BaseAdapter{
        Context context;
        int pos;
        int length;
        LayoutInflater layoutInflater;
        public static String[] Beverage={"PEPSI","COKE","LASSI","FALOODA","BUTTER MILK","GREEN TEA","BADAM MILK","MASALA CHAI" };
        public static String[] Beveragecos={"$ 0.5","$ 0.5","$ 2.0","$ 3.0","$ 1.5","$ 0.7","$ 0.8","$ 1.0"};
       public static String[] Breakfast={"SIRLOIN & EGG","CFS STEAK & EGG","T-BONE & EGG","TWO EGGS BREAKFAST","2EGG W/MEAT","BEL WAFFLE","BEL WAFFLE W/MEAT","BLUEBERRY CAKE","CAKES","FABULOUS FRENCH TST","MOONS","FRENCH TST"};
        public static String[] Breakfastcos={"$ 2.5","$ 3.0","$ 3.5","$ 2.7","$ 4.7","$ 3.0","$ 5.6","$ 3.0","$ 2.5","$ 3.2","$ 2.0","$ 1.0"};
        public static String[] Lunch={" CRAB CAKE SANDWICH","TUSCAN GRILLED CHICKEN PANINI","SOUTHWEST TURKEY CLUB"," LOBSTER ROLL","TUNA MELT"," FRENCH DIP","YOUR OWN SANDWICH"};
        public static String[] Lunchcos={"$ 4.0","$ 4.5","$ 7.0","$ 3.5","$ 5.5","$ 6.3","$ 5.0"};
        public static String[] Dinner={"DUBLIN BAY PRAWN","CRAB FROM BRITTANY","WHITE ASPARAGUS","BLEWIT MUSHROOM","JOHN DORY FISH","MONKFISH","VEAL SWEET BREAD","LAMB","PIGEON FRY"};
        public static String[] Dinnercos={"$ 3.5","$ 4.5","$ 3.3","$ 2.6","$ 4.3","$ 3.7","$ 2.5","$ 3.0","$ 4.0"};
        public static String[] Desserts={"ECHOURGNAC CHEESE","HAZELNUT","GARIGUETTE STRAWBERRY","MOUSSE & ZEST","APRICOT","CHOCOLATE"};
         public static String[] Dessertscos={"$ 1.0","$ 1.5","$ 2.7","$ 4.0","$ 2.9","$ 1.5"};
        public static String[] Appetizers={"Greek Artichoke Spinach","Seafood Appetizers","Tapenade Flatbread","Cranberry Blue Cheese","Fig and Blue Cheese","Sun-Dried Tomato","Tropical Crab Rangoon"};
        public static String[] Appertizerscos={"$ 1.3","$ 2.7","$ 1.5","$ 2.0","$ 2.5","$ 2.3","$ 3.0"};
    
        public CustomAdapter(Context context, int pos, int length) {
            super();
            this.context=context;
            this.pos=pos;
            this.length=length;
        }
    
        public int getCount() {
            return length;
        }
    
        public Object getItem(int position) {
            return position;
        }
    
        public long getItemId(int position) {
            return 0;
        }
    
        public View getView(int position, View convertView, ViewGroup parent) {
            DataHolder holder=null;
            if(convertView==null){
                holder=new DataHolder();
                layoutInflater=((Activity)context).getLayoutInflater();
                convertView=layoutInflater.inflate(R.layout.list_item, parent, false);
                holder.title=(TextView) convertView.findViewById(R.id.title);
                holder.price=(TextView) convertView.findViewById(R.id.price);
                convertView.setTag(holder);
            }
            else
            {
                holder=(DataHolder) convertView.getTag();
            }
            if(pos==1){
                holder.title.setText(Beverage[position]);
                holder.price.setText(Beveragecos[position]);
            }
            else if(pos==2){
                holder.title.setText(Breakfast[position]);
                holder.price.setText(Breakfastcos[position]);
            }
            else if(pos==3){
                holder.title.setText(Lunch[position]);
                holder.price.setText(Lunchcos[position]);
            }
            else if(pos==4){
                holder.title.setText(Dinner[position]);
                holder.price.setText(Dinnercos[position]);
            }
            else if(pos==5){
                holder.title.setText(Desserts[position]);
                holder.price.setText(Dessertscos[position]);
            }
            else if(pos==6){
                holder.title.setText(Appetizers[position]);
                holder.price.setText(Appertizerscos[position]);
            }
            return convertView;
        }
        static class DataHolder{
            TextView title,price;
        }
    
    }
    

    and list_item.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="30dp"
         >
    
        <TextView 
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />
    
        <TextView 
            android:id="@+id/price"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"/>
    
    
    </RelativeLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this below code access the ListView item value into string and display
I am trying to display ListView . I have created one activity , in
I have a custom listview and I am using a custom listadapter to display
I have created a custom ArrayAdapter to display data within ListView items from an
I have a custom listview which display an image, textview and radio button. I
I have a ListView which uses a custom adapter to display rows of data.
I have a custom listview in which one textview and one checked box is
I have a custom ListView which contains one TextView (Of numbers) and one EditText
I have a ListView which displays a list of string values. I want to
I want to display a ListView in table format. The ListView should have rows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.