怎样去除GridView长按返回后的选中效果??求助

装作睡不着 2014-12-29 10:21:03
是这样的,一个Gridview, android:listSelector="#123456" android:drawSelectorOnTop="true"来设置选中效果,按下后就会显示相应的效果,但是长按后弹出菜单,再按返回选中效果没有消失,这时怎么回事,求大神指点。图片如下 XML代码:<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<TextView
android:id="@+id/equalizerText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="均衡器"/>

<GridView
android:id="@+id/equalizerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="4"
android:horizontalSpacing="5dp"
android:verticalSpacing="5dp"
android:listSelector="#123456"
android:drawSelectorOnTop="true">
</GridView>

Java代码:
public class MainActivity extends Activity {
private GridView equalizerView;
private int select_position=1;
private int a;
SimpleAdapter simpleAdapter;
String [] E = {"正常","古典","舞曲","平直",
"民歌","重金属","嘻哈","爵士",
"流行","摇滚","增强器","自定义"};
int [] ID = {R.drawable.classical,
R.drawable.custom,
R.drawable.dance_song,
R.drawable.enhancer,
R.drawable.flat,
R.drawable.folk_song,
R.drawable.heavy_metal,
R.drawable.hip_hop,
R.drawable.jazz,
R.drawable.normal,
R.drawable.rock_and_roll,
R.drawable.pop};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.switch_layout);

equalizerView=(GridView) findViewById(R.id.equalizerView);
registerForContextMenu(equalizerView);
ArrayList<HashMap<String, Object>> imagelist = new ArrayList<HashMap<String, Object>>();
for (int i = 0; i < 12; i++) {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("image", ID[i]);
map.put("text", E[i]);
imagelist.add(map);
}
simpleAdapter = new SimpleAdapter(this, imagelist,
R.layout.grid_item, new String[] { "image", "text" }, new int[] {
R.id.item_image, R.id.item_text});
equalizerView.setAdapter(simpleAdapter);
@Override
public void onCreateContextMenu(final ContextMenu menu, final View v,final ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
menu.setHeaderTitle("wuwuw");
menu.add(0,1, 0,"a");
menu.add(0,2, 0,"b");
}
}
由于代码比较多,这只是部分代码,请谅解。其实不用看代码,有遇见过这类问题的朋友,给我点思路方法就行。感激不尽!!
...全文
191 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zzyyjj2003 2017-05-19
  • 打赏
  • 举报
回复
其实就是GridView默认事件,长按之后会默认触发单击事件
装作睡不着 2014-12-31
  • 打赏
  • 举报
回复
有没有人帮忙啊
装作睡不着 2014-12-30
  • 打赏
  • 举报
回复
引用 2 楼 Thorlen 的回复:
android:listSelector="@android:color/transparent"
这样点击也没有效果了,我要指定一张图片作为显示效果的。
Thorlen 2014-12-30
  • 打赏
  • 举报
回复
android:listSelector="@android:color/transparent"
红袖满楼招 2014-12-29
  • 打赏
  • 举报
回复
自己写selector就行了啊

80,350

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧