title: How to get the value from onItemClick ListView in Android
body: <p>I have a global variable <code>myval</code> which is of String type.</p>
  
  <pre><code>String[] Category={"----SELECT----","BEVERAGES","BREAKFAST","LUNCH","DINNER","DESSERTS","APPETIZERS &amp; SIDES"};
  String[] Beverage={"PEPSI","COKE","LASSI","FALOODA","BUTTER MILK","GREEN TEA","BADAM MILK","MASALA CHAI" };
  String[] Breakfast={"SIRLOIN &amp; EGG","CFS STEAK &amp; EGG","T-BONE &amp; EGG","TWO EGGS BREAKFAST","2EGG W/MEAT","BEL WAFFLE","BEL WAFFLE W/MEAT","BLUEBERRY CAKE","CAKES","FABULOUS FRENCH TST","MOONS","FRENCH TST"};
  String[] Lunch={" CRAB CAKE SANDWICH","TUSCAN GRILLED CHICKEN PANINI","SOUTHWEST TURKEY CLUB"," LOBSTER ROLL","TUNA MELT"," FRENCH DIP","YOUR OWN SANDWICH"};
  String[] Dinner={"DUBLIN BAY PRAWN","CRAB FROM BRITTANY","WHITE ASPARAGUS","BLEWIT MUSHROOM","JOHN DORY FISH","MONKFISH","VEAL SWEET BREAD","LAMB","PIGEON FRY"};
  String[] Desserts={"ECHOURGNAC CHEESE","HAZELNUT","GARIGUETTE STRAWBERRY","MOUSSE &amp; ZEST","APRICOT","CHOCOLATE"};
  String[] Appetizers={"Greek Artichoke Spinach","Seafood Appetizers","Tapenade Flatbread","Cranberry Blue Cheese","Fig and Blue Cheese","Sun-Dried Tomato","Tropical Crab Rangoon"};
  
  class GlobalClass extends Application {
       public static String[] myval;
  
  }   
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.home);
      spinner = (Spinner) findViewById(R.id.spinnerCategory);
      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&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_spinner_item, Category);
      adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      spinner.setAdapter(adapter);
      final ArrayAdapter&lt;String&gt; bever = new ArrayAdapter&lt;String&gt;(this,        android.R.layout.simple_list_item_1, Beverage);
  
      // Assign adapter to ListView
      final ArrayAdapter&lt;String&gt; Breakf = new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_1, Breakfast);
      final ArrayAdapter&lt;String&gt; lunc= new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_1, Lunch);     
      final ArrayAdapter&lt;String&gt; Dinn= new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_1, Dinner);     
      final ArrayAdapter&lt;String&gt; Dessert = new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_1, Desserts);     
      final ArrayAdapter&lt;String&gt; Appet= new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_1, Appetizers);     
  
      spinner.setOnItemSelectedListener(new OnItemSelectedListener(){
           public void onItemSelected(AdapterView&lt;?&gt; 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 &amp; SIDES")){
              l1.setAdapter(Appet);
              return;            
               }
           }
           public void onNothingSelected(AdapterView&lt;?&gt; arg0){
           }             
       });
       l1.setOnItemClickListener(new OnItemClickListener() {
  
           public void onItemClick(AdapterView&lt;?&gt; 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();
                long ii=(long) l1.getItemIdAtPosition((int) id);
                //Get the value from listView click item                   
                String[] S5=new String[]{a5};
                //String[] S1=new String[]{s2};
                GlobalClass.myval=S5;
          });            
          b1.setOnClickListener(new View.OnClickListener() {
  
              public void onClick(View v) {
  
                   String tno = e1.getText().toString();
                   int tn = Integer.parseInt(tno);
  
                   Intent i=new Intent(getApplicationContext(),TicketActivity.class);
                   Bundle b=new Bundle();
                   b.putInt("Table No:", tn);
                   i.putExtras(b);
                   String et= e2.getText().toString();
                   int et1 = Integer.parseInt(et);
                   Bundle be=new Bundle();
                   be.putInt("Guest:", et1);
                   i.putExtras(be); 
  
                   startActivity(i);                    
              }
          });            
          b3.setOnClickListener(new View.OnClickListener() {
  
              public void onClick(View v) {
                  Intent intent=new Intent(HomeActivity.this,PaynowActivity.class);
                  startActivity(intent);
              }
          });             
          b2.setOnClickListener(new View.OnClickListener() {
  
              public void onClick(View v) {
                  Intent m=new Intent(HomeActivity.this,OrderinfoActivity.class);
                  startActivity(m);
              }
          });
      }        
  } 
  </code></pre>
  
  <p>How do I get the value from <code>onItemClick</code> in the ListView?</p>