android listview拖拽,拖動item 改變位置
在packages/apps/Music/src/touchIncepter.java中
該類提供了listview的拖動效果,並提供介面,在程式介面中實現資料的交換即可。
- package com.and.DragListview;
- import java.util.ArrayList;
- import java.util.List;
- import android.app.ListActivity;
- import android.content.Context;
- import android.os.Bundle;
-
import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.BaseAdapter;
- import android.widget.ImageView;
- import android.widget.TextView;
- publicclass DragListview extends ListActivity {
- MyAdapter adapter;
- TouchInterceptor list;
-
List<String> arrayText;
- @Override
- publicvoid onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- list = (TouchInterceptor) getListView();//(TouchInterceptor)findViewById(android.R.id.list);
- getText();
-
adapter = new
- setListAdapter(adapter);
- list.setDropListener(mDropListener);
- // list.setRemoveListener(mRemoveListener);
- }
- publicvoid getText(){
- arrayText = new ArrayList<String>();
- arrayText.add("傳奇");
- arrayText.add("紅豆");
- arrayText.add("流年");
- arrayText.add("棋子");
- }
- //交換listview的資料
- private TouchInterceptor.DropListener mDropListener =
- new TouchInterceptor.DropListener() {
- publicvoid drop(int from, int to) {
- String item = arrayText.get(from);
- arrayText.remove(item);//.remove(from);
- arrayText.add(to, item);
- adapter.notifyDataSetChanged();
- }
- };
- private TouchInterceptor.RemoveListener mRemoveListener =
- new TouchInterceptor.RemoveListener() {
- publicvoid remove(int which) {
- }
- };
- class MyAdapter extends BaseAdapter{
- private LayoutInflater mInflater;
- Context mContext;
- public MyAdapter(Context c){
- mInflater = LayoutInflater.from(c);
- }
- publicint getCount() {
- return arrayText.size();
- }
- public Object getItem(int arg0) {
- return arrayText.get(arg0);
- }
- publiclong getItemId(int arg0) {
- return arg0;
- }
- public View getView(int arg0, View contentView, ViewGroup arg2) {
- ImageView img;
- TextView text;
- if(contentView==null){
- contentView = mInflater.inflate(R.layout.list_layout, null);
- //contentView = mInflater.inflate(R.layout.list_layout,null);
- }
- img = (ImageView)contentView.findViewById(R.id.img);
- img.setBackgroundResource(R.drawable.icon);
- text = (TextView)contentView.findViewById(R.id.text);
- text.setText(arrayText.get(arg0).toString());
- return contentView;
- }
- }
- }
原始碼中的類:
- /*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- package com.and.DragListview;
- import android.content.Context;
- import android.content.SharedPreferences;
- import android.content.res.Resources;
- import android.graphics.Bitmap;
- import android.graphics.PixelFormat;
- import android.graphics.Rect;
- import android.util.AttributeSet;
- import android.view.GestureDetector;
- import android.view.Gravity;
- import android.view.MotionEvent;
- import android.view.View;
- import android.view.ViewConfiguration;
- import android.view.ViewGroup;
- import android.view.WindowManager;
- import android.view.GestureDetector.SimpleOnGestureListener;
- import android.widget.AdapterView;
- import android.widget.ImageView;
-
相關推薦
android listview拖拽,拖動item 改變位置
在packages/apps/Music/src/touchIncepter.java中 該類提供了listview的拖動效果,並提供介面,在程式介面中實現資料的交換即可。 package com.and.DragListvie
如何在Listview中拖拽其中的子Item移動其位置
最近開發遇到一個需求,需要顯示的物件支援拖拽,一般的物件直接使用dargarea即可。但我用的是Listview來顯示,而且是自己定義的listmodel,可以說是相當的煩。 1、一種情況,如果是使用qml中的listmodel則直接呼叫model的move方法進行移動:核心程式碼為 &nb
Android 使用變形矩陣實現可以拖拽,縮放,旋轉的影象
上篇博文介紹了變形矩陣的一些用法,所以這篇博文就結合變形矩陣來實現一個可以拖拽、縮放、旋轉的影象吧。 首先,我們就繼承ImageView來實現我們的自定義View。 程式碼如下: public class MyMatrixImg extends Ima
模擬點選,滑鼠移動,拖拽,按鍵,下拉框的處理
1.模擬點選 from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains from time import sleep driver = webdriver.Chrom
安卓實現任意控制元件view可拖拽,並監聽拖拽和點選事件,可自動拉回螢幕邊緣
因為專案中有需要實現控制元件可任意拖拽的需求,所以簡單寫了個自定義OnTouchListener,以作拋磚引玉,歡迎大家提議反饋。 完整實現類如下,程式碼中有詳細註釋: 使用者可以決定是否開啟自動拖拽邊緣功能,可以監聽控制元件的拖拽和點選事件 public cl
RecyclerView實現條目拖拽,左滑、右滑移除效果
對於android開發者來說RecyclerView應該已經很熟悉了,專案中基本都是使用RecyclerView來實現列表效果,這裡要實現的是RecyclerView的條目拖拽、左滑、右滑移除效果,這些效果都是在RecyclerView列表基礎上來實現的,所以還是先簡單的實現RecyclerVi
QML實現的無邊框視窗的拉伸,拖拽,基本解決閃爍嚴重問題
使用qt製作的無邊框視窗,只需在其flag中加入FramelessWindowHint。然而,無邊框視窗意味著,無法使用原有的邊框拉伸,拖拽功能。在qwidget中,有很多實現的方法,比如重寫 + mouseMoveEvent(QMouseEvent *event)
一個可拖拽,移動,自由組合子控制元件的檢視控制元件,讓開發更簡單
今天給大家推薦一個自由拖拽,自由組合的控制元件,這個控制元件是我自定義寫的。通過它,我們可以自由拖拽,自由組合實現一個介面,滿足一個使用者自由組合介面的需求。這裡不是通過自由拖拽控制元件,來快速開發一個介面,而且更人性化的讓使用者去自由組合一個介面。 前言
使用UGUI實現揹包物體的拖拽,交換等操作
本例項通過UGUI實現揹包的簡單功能,物品的拖拽,交換,拖放位置處理,還有針對揹包多頁面的滑動翻頁的處理。 具體的程式碼如下。 首先是UIItem類,這個揹包內各種物體的類: using UnityEngine; using System.Collections; usi
html5拖拽,要在ondragover阻止這個預設事件,和解決火狐上的相容問題
在火狐上不相容這一套: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <styl
如何解決div裡面的h4標題拖拽,並且實現div裡面的文字能夠選中和不能選中的問題
<!doctype html> <html> <head> <meta charset="utf-8"> <title>無標題文件</title> <style> *{ margin:0;
android 輸入法彈出鍵盤把listview頂上去,保留頂部標題欄位置不動
文章出處:http://blog.csdn.net/xingCome/article/details/51424724 只為記錄。 一:給listview 設定屬性 android:transcriptMode="normal"(必須) android:fastSc
支援多檔案上傳,預覽,拖拽,基於bootstrap的上傳外掛fileinput的ajax非同步上傳
首先需要匯入一些js和css檔案 <link href="__PUBLIC__/CSS/bootstrap.css" rel="stylesheet"> <link type="text/css" rel="stylesheet" href="__
自定義拖拽事件時,div可以拖拽,img拖不了的解決方法
原因:未阻止事件流和預設事件 解決方法: function pauseEvent(e){ //已做相容性處理 if(e.stopPropagation) e.stopPropagation(); if(e.preventDefault) e.pre
適合pc端的移動拖拽,分享一下。
h5新加的特性拖拽事件,但是隻適合PC端哦。不多說了上程式碼 <!DOCTYPE html>
Android ListView動態刷新某項Item
ack static auto ids avi idt ica horizon extc 使用ViewHolder來刷新某項數據,而不用每次都全部刷新數據。 繼承BaseAdapter,新建ViewHolder類。 public class TestListAdap
詳細講解html5拖拽和拖放技術的區別及優勢
提到拖拽,我們都很熟悉,那麼拖放呢?一字之差,代表的意義是不一樣的,拖拽就是拉著走,拖放就是有拖,有放,我們都知道原生 JS 拖拽效果的缺點:1. 程式碼相對複雜與冗餘2. 僅限於在瀏覽器內的元素間拖放3、不能實現跨頁面的拖放 所以H5就出現了拖放技術,與 JS 原生相比 HTML5 拖放的優勢
HTML5 drag & drop 拖拽與拖放
執行 javascrip eve eight 觸發 元素 padding 軟件 測試 關鍵詞: 1. draggable:規定元素是否可拖動的,draggable=true可拖動 2. dataTransfer:拖拽對象用來傳遞的媒介,使用方式:event.dataTran
Android ListView功能擴充套件,實現高效能的瀑布流佈局
經過前面兩篇文章的學習,我們已經對ListView進行了非常深層次的剖析,不僅瞭解了ListView的原始碼和它的工作原理,同時也將ListView中常見的一些問題進行了歸納和總結。那麼本篇文章是我們ListView系列三部曲的最後一篇,在這篇文章當中我們將對ListView
Android ListView效能優化,非同步載入圖片
<span style="font-size:14px;"><span style="font-size:14px;">public static void initImageLoader(Context context) { personOptions = new D