2015-09-21 115 views
0

我已经创建了一个列表视图的活动,并增加页脚视图语法。页脚视图包含两个按钮(返回&下一个)。问题是,当我点击按钮它不会触发点击事件,但当我专注于查看(脚注)它触发点击事件。如何在列表视图页脚视图按钮添加点击监听

这里是我的代码,

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(); 
 
          } 
 
         });

在此先感谢。添加页脚视图 前

+0

无论有没有下面帮你的答案?如果是这样,请标记哪一个,谢谢:) –

回答

0

撰写您OnclickListener并确保设置可聚焦=“假”中的XML到根布局

0

在用于充气footer_controls的XML布局,尝试把android:descendantFocusability="blocksDescendants"上最高的根视图

例如

<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> 
0

低于它为我工作的代码的Try ...没有必要持有人打电话给你的按钮就可以直接findviewbyid如下

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(); 
         } 
        }); 
相关问题