C#怎样为ListView添加双击事件

C#怎样为ListView添加双击事件,第1张

直接在 右击“ListView”属性,在出现属性的那个栏中的上面有个 闪电 的按钮,单击那个,就会出现这个"ListView"的所有事件,在里面找到一个doubleclick 的,在这的右边双击进去就会自动产生双击事件函数,

Form1.Designer.cs里面也会自动添加这个双击事件

你是的意思是在listView的每一项里都加一个固定的按钮或图片吗,那就将它写到一个xml中,然后inflate到listView中,这样listView的每一项的布局就都是xml中的布局了。

<LinearLayout xmlns:android="

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

<Button

android:id="@+id/button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Button"

/>

<ListView

android:id="@+id/listView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

/>

</LinearLayout>

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState)

setContentView(R.layout.listview)

String[] data = {"a", "b", "c", "d", "a", "b", "c", "d", "a", "b", "c", "d"}

ListView listView = (ListView) findViewById(R.id.listView)

listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, data))


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11242549.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-14
下一篇 2023-05-14

发表评论

登录后才能评论

评论列表(0条)

保存