I have created activity with a listview, and adding footer view grammatically. Footer view consists two button(back & next). The issue is when i click on button it doesn't fires click event but when i focus to View(footerview) it trigger click event.
here is my code,
listView.addFooterView(footer_controls,null,true); Button NextButton =(Button) footer_controls.findViewById(R.id.btnNext); NextButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(context, "forward clicked", Toast.LENGTH_LONG).show(); LoadData(); } });
Thanks in advance.
在添加页脚视图之前,请编写OnclickListener并确保将xml内的focusable =“ false”设置为根布局
In the xml layout used for inflating footer_controls, try putting android:descendantFocusability="blocksDescendants"
on the highest root view
For example
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical" >
<Button ...>
<!--Other Views -->
</LinearLayout>
Try below code it worked for me... there is no need of holder to call your button you can directly findviewbyid as follow
listSearchResult = (ListView) findViewById(R.id.listSearchResult);
footerView1 = View.inflate(this, R.layout.no_listing_found, null);
listSearchResult.addFooterView(footerView1,null,false);
Button NextButton =(Button) findViewById(R.id.btnNext);
NextButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, "forward clicked", Toats.LENGTH_LONG).show();
LoadData();
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.