android长按listview
① 为什么 Android 的应用上较少左(右)划删除,大多是长按删除
Android 应用少采用向左向右滑动删除,大多数为长按删除的原因如下:
向左向右滑动,需要给每个listview的item单独的加上很多代码来控制显示和隐藏文字,更容易出现bug。
长按删除这一操作,是从android系统推出以来就有的功能,便于用户操作,积累了操作习惯。
Android点击事件分为点击事件和长按事件,两个事件可以单独进行相应的,底层就是识别接触点,回调执行相应的业务逻辑。
② android微信的聊天记录长按某聊天弹出的页面是怎样实现的
Android中应该是用ListView来实现聊天记录的,长按某个记录后,如果设置了侦听器:
setOnItemLongClickListener(OnItemLongClickListener listener);
则listener中的方法: boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) 将被调用,你可以实现这个方法,在其中创建你想要的对话框。
全屏对话框可以这样实现:
1 如果你请求activity去创建,则showDialog(YOUR_DIALOG_ID);
然后在activity中的
@OverrideprotectedDialog onCreateDialog(int id){//all other dialog stuff (which dialog to display)//this line is what you need:
dialog.getWindow().setFlags(LayoutParams.FLAG_FULLSCREEN,LayoutParams.FLAG_FULLSCREEN);return dialog;
}
2 如果直接创建,则调用:Dialog dialog=newDialog(this,R.style.Theme_Dark_NoTitleBar_FullScreen);
不知道有没有说清楚。
③ Android 怎么获取所有正在运行的应用程序
在framework中想添加这个功能,所以写了个appliction来实现一下获取正在运行的应用程序: 还是先看图吧: 这个app主要是简单的实现了获取非系统的应用程序和一些常用的系统应用程序,显示在一个listview中,并添加了点击(回复到你打开的界面)和长按事件(关闭应用程序)。 看看代码吧: 直接贴出来再加上注释吧(直接写在一个文件里): package andorid/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:layout_width="40dip" android:layout_height="40dip" /> <LinearLayout android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textStyle="bold" /> <TextView android:id="@+id/info" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> </LinearLayout> main: <?xml version="1/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ListView android:id="@+id/list_view" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" ></ListView> </LinearLayout> 在manifest文件中要加以个权限: <uses-permission android:name="android.permission.RESTART_PACKAGES" /> 主要是前面的am.killBackgroundProcesses(packageName);方法要这个权限。
④ Android listview长按拖动,背景变黑,怎么处理
其实这个问题发生的原因在于ListView存在缓存颜色机制,因此我们可以通过设定缓存颜色为透明的方法来解决这个问题。
A、通过布局属性来设定(ListView的属性中直接定义)
android:cacheColorHint=”#00000000″
B、在代码中直接设定
listView.setCacheColorHint(Color.TRANSPARENT);
这样就可以解决黑色出现的问题了。