我在RelativeLayout中有这个Button,它包含在自定义ListView行Layout的一部分中。
<Button
p1:text="Edit"
p1:layout_width="75dp"
p1:layout_height="wrap_content"
p1:id="@+id/editButton"
p1:layout_centerHorizontal="true"
p1:background="@drawable/btn_blue"
p1:textColor="@color/white"
p1:focusable="false"
p1:layout_below="@id/sparyTableLayout"
p1:textAppearance="?android:attr/textAppearanceMedium"
p1:onClick="myClickHandler" />
当用户单击Button时,我希望Button调用此函数:
public void myClickHandler(View v)
{
Console.WriteLine ((v as Button).Text);
}
但是,我收到了这个错误
java.lang.IllegalStateException: Could not find a method myClickHandler(View) in the activity class Test_Project.MyActivity for onClick handler on view class android.widget.Button with id 'editButton'
我试图区分我在ListView中的不同按钮。此外,每行有多个按钮。
编辑:
不要在按钮中使用标签,它可能会导致ListView滚动期间性能下降。以下解决方案是更好的选择。