如何在c#ListView中加入按钮

如何在c#ListView中加入按钮,第1张

Button button = new Button()

button.Text = "测试"

button.Location = listView1.Location

listView1.Controls.Add(button)

你是的意思是在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://54852.com/bake/11530710.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存