android ListView如何获取点击item所在的哪一行

android ListView如何获取点击item所在的哪一行,第1张

1、在listitem中初始化button的时候,给该button添加一个setTag方法,将此时的索引值传进去,然后在button的onclick事件中调用view的getTag方法,即可将listitem的索引读出来,代码如下:

tagButtonsetTag(position);

此处的tagButton就是定义的button,Position是view里边的位置。

2、初始化button的时候通过setTag方法传入一个item的索引值

private OnClickListener tagButtonOnClick = new OnClickListener() {

public void onClick(View v) {

final int index = (Integer) vgetTag();

index就是点击button所在Item中的位置,通过这个位置就可以得到Item中的值。

foreach(ListViewItem item in listviewItems)

{

if(listviewItemsChecked == true)

{

string message = “”;

}

}

private void CreateMyListView()

{

// Create a new ListView control

ListView listView1 = new ListView();

listView1Bounds = new Rectangle(new Point(10,10), new Size(300,200));

// Set the view to show details

listView1View = ViewDetails;

// Allow the user to edit item text

listView1LabelEdit = true;

// Allow the user to rearrange columns

listView1AllowColumnReorder = true;

// Display check boxes

listView1CheckBoxes = true;

// Select the item and subitems when selection is made

listView1FullRowSelect = true;

// Display grid lines

listView1GridLines = true;

// Sort the items in the list in ascending order

listView1Sorting = SortOrderAscending;

// Create three items and three sets of subitems for each item

ListViewItem item1 = new ListViewItem("item1",0);

// Place a check mark next to the item

item1Checked = true;

item1SubItemsAdd("1");

item1SubItemsAdd("2");

item1SubItemsAdd("3");

ListViewItem item2 = new ListViewItem("item2",1);

item2SubItemsAdd("4");

item2SubItemsAdd("5");

item2SubItemsAdd("6");

ListViewItem item3 = new ListViewItem("item3",0);

// Place a check mark next to the item

item3Checked = true;

item3SubItemsAdd("7");

item3SubItemsAdd("8");

item3SubItemsAdd("9");

// Create columns for the items and subitems

listView1ColumnsAdd("Item Column", -2, HorizontalAlignmentLeft);

listView1ColumnsAdd("Column 2", -2, HorizontalAlignmentLeft);

listView1ColumnsAdd("Column 3", -2, HorizontalAlignmentLeft);

listView1ColumnsAdd("Column 4", -2, HorizontalAlignmentCenter);

//Add the items to the ListView

listView1ItemsAddRange(new ListViewItem[]{item1,item2,item3});

// Create two ImageList objects

ImageList imageListSmall = new ImageList();

ImageList imageListLarge = new ImageList();

// Initialize the ImageList objects with bitmaps

imageListSmallImagesAdd(BitmapFromFile("C:\\MySmallImage1bmp"));

imageListSmallImagesAdd(BitmapFromFile("C:\\MySmallImage2bmp"));

imageListLargeImagesAdd(BitmapFromFile("C:\\MyLargeImage1bmp"));

imageListLargeImagesAdd(BitmapFromFile("C:\\MyLargeImage2bmp"));

//Assign the ImageList objects to the ListView

listView1LargeImageList = imageListLarge;

listView1SmallImageList = imageListSmall;

// Add the ListView to the control collection

thisControlsAdd(listView1);

}

For Each itm As ListViewItem In MeListView1Items

DebugPrint(itmSubItems(0)Text) '显示每行的第一列

Next

以上就是关于android ListView如何获取点击item所在的哪一行全部的内容,包括:android ListView如何获取点击item所在的哪一行、C#如何获取listview选中项、vb.net ListView1中只有一列,怎么获得所有子项的索引,或者怎么计算一共有多少行不是选中项,是所有.等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

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

原文地址:https://54852.com/web/9311284.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存