【发布时间】:2013-12-10 11:03:53
【问题描述】:
我在 RelativeLayout 中有这个 Button,它作为自定义 ListView 行布局的一部分。
<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 中的不同按钮。此外,每一行都有多个按钮。
编辑:
不要在 Buttons 中使用标签,这会导致 ListView 滚动期间性能下降。下面的解决方案是更好的选择。
【问题讨论】: