【慢慢学Android】:10.处理listview长按事件,删除所选项

listview.setOnItemLongClickListener(new OnItemLongClickListener() {
			@Override
			public boolean onItemLongClick(AdapterView<?> parent, View view,
					int position, long id) {
				String item = (String) listview.getItemAtPosition(position);

				SharedPreferences Addresses = getSharedPreferences(FileListenerActivity.PREFS_NAME, 0);
				SharedPreferences.Editor editor = Addresses.edit();
				editor.remove(item);
				editor.commit();
				
				Toast.makeText(getBaseContext(), item + "被删除了",
						Toast.LENGTH_SHORT).show();
				
				 list.remove(item);
				 adapter.notifyDataSetChanged();

				return true;
			}

		});

  

转载于:https://www.cnblogs.com/VortexPiggy/archive/2012/06/06/2537684.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现横向的 `ListView`,可以在外层 `ListView` 的 `orientation` 属性设置为 `ListView.Horizontal`。同时,需要将内层 `ListView` 的宽度设置为外层 `ListView` 每个选项的宽度之和,以确保内层选项能够全部展示出来,可以通过外层 `ListView` 的 `contentWidth` 属性来获取。 下面是修改后的示例代码: ```qml import QtQuick 2.0 import QtQuick.Controls 2.5 ListView { id: outerListView width: 400 height: 50 orientation: ListView.Horizontal model: outerModel delegate: ItemDelegate { text: model.label width: 100 ListView { id: innerListView width: outerListView.contentWidth height: 50 model: model.children visible: expanded orientation: ListView.Horizontal delegate: ItemDelegate { text: model.label width: 100 highlight: checked ? Rectangle { color: "lightblue" } : null onClicked: { if (multiSelect) { checked = !checked; } else { outerListView.currentIndex = -1; checked = true; } } } } Rectangle { id: expandIcon anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter width: 10 height: 10 color: "black" transform: expanded ? Rotation { origin.x: 5; origin.y: 5; angle: 90 } : Rotation { origin.x: 5; origin.y: 5; angle: 0 } MouseArea { anchors.fill: parent onClicked: expanded = !expanded } } property bool expanded: false property bool multiSelect: false property bool checked: false } } ``` 这样,就可以通过设置 `orientation` 属性将外层 `ListView` 设置为横向,同时将内层 `ListView` 的宽度设置为外层 `ListView` 每个选项的宽度之和,来实现横向的 `ListView` 了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值