Android 中 GridView 内的可点击 TextView
我在 android 中有一个 GridView,我用在 BaseAdapter 类的重写方法 getView 中创建的 TextView 填充它。最初创建的TextView的onClick方法并没有实现,而是执行按下的感觉。但是当我实现 TextView 的 onClick 时,它执行了 onClick 操作,但按下的感觉消失了。
有没有一种方法,即使实现了 onClick 方法,我也能感受到按下的 TextView 工作的感觉?
感谢
更新 大家好,返回 false 不起作用,它显示编译错误。我想做的是这样的: 在 BaseAdapter 内部填充 GridView
public View getView(int position, View convertView, ViewGroup parent) {
TextView v;
if(convertView == null){
v = new TextView();
}else{
v = (TextView) convertView;
}
}
此时 TextView 可以聚焦并具有单击视图的感觉。 但是,如果我像这样实现 onClickListener,我可以执行该操作,但按下视图(或聚焦)的感觉消失了:
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
deleteHour(mapDays.get(day));
}
});
我可以看到 GridView 中有一个 onClick 事件,而 TextView 中有另一个 onClick 事件。我认为当我在 TextView 中实现 onClick 方法时,它会禁用 GridView 中的 onClick 。
也许问题是,如何使 TextView 可单击并在单击时更改 TextView 的状态?你有什么想法吗?
非常感谢您的回复!
I have a GridView in android and i am populating it with TextView created inside the overrided method getView of BaseAdapter class. Initially the onClick method of the created TextView is not implemented, but performs the sense of pressed. But when i implement the onClick of the TextView, it does the onClick actions, but the sense of pressed is gone.
Is there a way that i can have the sense of a pressed TextView work even with the method onClick implemented?
Thanks
Updating
hi people, the return false didn't work it shows compilation error. What i am trying to do is somiething like this: Inside the BaseAdapter to populate the GridView
public View getView(int position, View convertView, ViewGroup parent) {
TextView v;
if(convertView == null){
v = new TextView();
}else{
v = (TextView) convertView;
}
}
At this point the TextView can be focused and has the sense of clicked view.
But if i implement the onClickListener like that, i can perform the action but the sense of pressed view (or focused) is gone:
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
deleteHour(mapDays.get(day));
}
});
I can see that there is an onClick event in GridView and another one in TextView. I think that when i implement the onClick method in the TextView it disables the onClick in GridView.
Maybe the question is, how to make a TextView clickable changing the state of the TextView when it is clicked? Have you got any ideas?
Thanks a lot for the replies!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我做到了!
我发现的方法是重写 GridView 的 setOnItemClickListener,如下所示:
我希望这可以帮助任何遇到同样问题的人!
谢谢!
i did it!
The way that i found is to override the setOnItemClickListener of the GridView like this:
I hope this helps anyone with the same problem!
Thanks!