3 回答

TA貢獻1836條經驗 獲得超5個贊
這很簡單,您使用 id 的方式與您使用 TextView 的方式相同
所以你的按鈕看起來像這樣:
<Button
android:id="@+id/buttonId"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
現在在您的點擊事件中,您可以使用位置參數來找出列表中的哪個元素正在接收點擊,例如:
var btn = view.FindViewById<Button>(Resource.Id.buttonId);
btn.Clicked+= (s,e)=>
{
if(position==someValue)
{//Code}
else
{//Code}
};

TA貢獻2003條經驗 獲得超2個贊
在您的 XML 中:
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
對于你的活動:
Button btn = view.FindViewById<Button>(Resource.Id.btn);
btn.Clicked+= btn_click;
private void LiveLeadSearch_Click(object sender, EventArgs e)
{
//Your implementation
}

TA貢獻1802條經驗 獲得超6個贊
您可以在 GetView 方法中編寫此代碼:
var btn = view.FindViewById<Button>(Resource.Id.buttonId);
btn.Tag=position;
btn.SetOnClickListener(this);
在您的適配器中實現“View.IOnClickListener”并覆蓋 Onclick 方法后
public void OnClick(View v)
{
switch (v.Id)
{
case Resource.Id.buttonId:
//Write code here
break;
}
}
- 3 回答
- 0 關注
- 132 瀏覽
添加回答
舉報