如何在ListView上使用Button的onClickListener方法

det*_*o29 5 android button android-listview onclicklistener

我有一个ListView包含a 的自定义Button.此按钮的功能是删除按钮.每当用户单击此按钮时,将删除当前行.

  • 我该怎么做?
  • 如何设置onClickListener此按钮?
  • 如何捕获此按钮所在的行ID?

提前致谢.

use*_*305 7

在您的Custom Adapater类中getView()

buttonDelete.setOnClickListener(new OnClickListener()
{
  @Override
  public void onClick(View v)
   {
     //  Use position parameter of your getView() in this method it will current position of Clicked row button
    // code for current Row deleted...              
   }
});
Run Code Online (Sandbox Code Playgroud)