Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 24th, 2012  |  syntax: None  |  size: 2.97 KB  |  hits: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Howto add onclick event to button in listview added by addheaderView?
  2. enter code here
  3.        
  4. super.onCreate(savedInstanceState);
  5.         setContentView(R.layout.games_by_category);
  6.  
  7.         Global globalclass=((Global)getApplicationContext());
  8.         globalclass.setpageno(0);                  
  9.         lstview =(ListView)findViewById(android.R.id.list);      
  10.  
  11.         LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);            
  12.         View v = inflater.inflate(R.layout.header, null);
  13.         //View v = getLayoutInflater().inflate(R.layout.header, null);
  14.         v.setMinimumHeight(10);
  15.         lstview.addHeaderView(v);
  16.  
  17.         btnhome=(Button)findViewById(R.id.btnHome);
  18.         btnhome.setOnClickListener(new View.OnClickListener() {
  19.  
  20.             public void onClick(View v)
  21.             {
  22.                 btnhome.setTextColor(Color.BLACK);
  23.                 Global globalclass=((Global)getApplicationContext());
  24.                 Intent inte=new Intent(GamesByCatActivity.this,HotGamesActivity.class);
  25.                 startActivity(inte);                    
  26.           }
  27.         });
  28.        
  29. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  30.     android:orientation="vertical" android:layout_width="match_parent"
  31.     android:layout_height="match_parent">
  32.     <ListView android:layout_width="fill_parent" android:layout_height="wrap_content"  android:id="@+id/_lv_babies" >
  33.     </ListView>
  34.           <RelativeLayout  android:layout_width="fill_parent"
  35.         android:layout_height="wrap_content" android:background="@color/blue_email"
  36.         >
  37.         <Button android:layout_width="wrap_content"
  38.             android:layout_height="wrap_content"
  39.             android:text="Edit" android:textSize="15dp" android:padding="10dp"
  40.             android:layout_margin="5dp" android:textColor="@color/black"
  41.             android:id="@+id/_btn_edit"/>
  42.         <Button android:layout_width="wrap_content"
  43.             android:layout_height="wrap_content"
  44.             android:text="Add" android:textSize="15dp" android:padding="10dp"
  45.             android:layout_margin="5dp" android:textColor="@color/black"
  46.              android:id="@+id/_btn_add"/>
  47.  
  48. </RelativeLayout>
  49. </LinearLayout>
  50.        
  51. View header;
  52. Button headerButton = header.findViewById(R.id.btn1);
  53. headerButton.setOnClickListener(this);
  54. listView.addHeaderView(header);
  55.        
  56. For your button click....if its works then tick on right click or accept my answer.
  57. protected void setXmlComponents(){
  58.         _btn_add =(Button)findViewById(R.id._btn_add);
  59.         _btn_edit =(Button)findViewById(R.id._btn_edit);
  60.             }
  61.     protected void setListener(){
  62.         _btn_add.setOnClickListener(new OnClickListener() {
  63.  
  64.             public void onClick(View v) {
  65.                 // TODO Auto-generated method stub
  66.                             }
  67.         });
  68.       _btn_edit.setOnClickListener(new OnClickListener() {
  69.  
  70.             public void onClick(View v) {
  71.                 // TODO Auto-generated method stub
  72.  
  73.             }
  74.         });
  75.  
  76.     }