- Howto add onclick event to button in listview added by addheaderView?
- enter code here
- super.onCreate(savedInstanceState);
- setContentView(R.layout.games_by_category);
- Global globalclass=((Global)getApplicationContext());
- globalclass.setpageno(0);
- lstview =(ListView)findViewById(android.R.id.list);
- LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
- View v = inflater.inflate(R.layout.header, null);
- //View v = getLayoutInflater().inflate(R.layout.header, null);
- v.setMinimumHeight(10);
- lstview.addHeaderView(v);
- btnhome=(Button)findViewById(R.id.btnHome);
- btnhome.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v)
- {
- btnhome.setTextColor(Color.BLACK);
- Global globalclass=((Global)getApplicationContext());
- Intent inte=new Intent(GamesByCatActivity.this,HotGamesActivity.class);
- startActivity(inte);
- }
- });
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical" android:layout_width="match_parent"
- android:layout_height="match_parent">
- <ListView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/_lv_babies" >
- </ListView>
- <RelativeLayout android:layout_width="fill_parent"
- android:layout_height="wrap_content" android:background="@color/blue_email"
- >
- <Button android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Edit" android:textSize="15dp" android:padding="10dp"
- android:layout_margin="5dp" android:textColor="@color/black"
- android:id="@+id/_btn_edit"/>
- <Button android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Add" android:textSize="15dp" android:padding="10dp"
- android:layout_margin="5dp" android:textColor="@color/black"
- android:id="@+id/_btn_add"/>
- </RelativeLayout>
- </LinearLayout>
- View header;
- Button headerButton = header.findViewById(R.id.btn1);
- headerButton.setOnClickListener(this);
- listView.addHeaderView(header);
- For your button click....if its works then tick on right click or accept my answer.
- protected void setXmlComponents(){
- _btn_add =(Button)findViewById(R.id._btn_add);
- _btn_edit =(Button)findViewById(R.id._btn_edit);
- }
- protected void setListener(){
- _btn_add.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- // TODO Auto-generated method stub
- }
- });
- _btn_edit.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- // TODO Auto-generated method stub
- }
- });
- }