在点击ImageView的非法状态,背景(选择) [英] Illegal state on click imageview with background (selector)

查看:252
本文介绍了在点击ImageView的非法状态,背景(选择)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经appwidget与集合(列表视图)。源部件XML布局:

I have appwidget with collection (listview). Source widget xml layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/widget_list_background"
    android:orientation="vertical"
    android:paddingBottom="3dip"
    android:paddingLeft="6dip"
    android:paddingRight="6dip"
    android:paddingTop="3dip" >
<!-- Header -->

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:orientation="horizontal" >

    <!-- App icon -->

    <ImageView
        android:id="@+id/widget_list_icon"
        android:layout_width="32dip"
        android:layout_height="32dip"
        android:layout_marginRight="3dip"
        android:src="@drawable/airplane" />

    <!-- Mailbox -->

    <TextView
        android:id="@+id/widget_list_account"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:maxLines="2"
        android:text="john@foo.com"
        android:textColor="@color/widget_text_primary" />

    <!-- Unread count -->

    <TextView
        android:id="@+id/widget_list_unread"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="3dip"
        android:text="12"
        android:textColor="@color/widget_text_secondary"
        android:textStyle="bold" />
</LinearLayout>

<!-- Overflow menu -->

<ImageView
    android:id="@+id/widget_list_overflow"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/simple_button_holo"
    android:paddingLeft="4dip"
    android:paddingRight="4dip"
    android:src="@drawable/toolbar_overflow" />

<!-- Line -->

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="1dip"
    android:layout_marginBottom="3dip"
    android:layout_marginTop="3dip"
    android:background="@color/widget_list_line" />

<!-- Listview with messages -->

<ListView
    android:id="@+id/widget_email_list"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<!-- Removed -->

<TextView
    android:id="@+id/widget_list_removed"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:text="@string/widget_removed_account"
    android:textColor="@color/widget_text_primary"
    android:textSize="18dip"
    android:textStyle="bold"
    android:visibility="gone" />

<!-- Empty list -->

<TextView
    android:id="@+id/widget_list_empty_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:text="@string/widget_inbox_empty"
    android:textColor="@color/widget_text_primary"
    android:textSize="18dip"
    android:textStyle="bold"
    android:visibility="gone" />

</LinearLayout>

在布局中存在的ImageView(widget_list_overflow)。我设置ImageView的背景:simple_button_holo

At layout exists imageview (widget_list_overflow). I set imageview background: simple_button_holo

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_focused="true"
          android:drawable="@drawable/simple_button_focused_holo" />

    <item android:state_pressed="true"
          android:drawable="@drawable/simple_button_pressed_holo" />

    <item android:drawable="@android:color/transparent" />
</selector>

问题:的ImageView 不仅对的ImageView ,但总体上点击亮点布局,其中的ImageView 包含。但是,为什么不仅在点击的ImageView

Issue: ImageView highlights on click not only on ImageView, but on whole layout, where ImageView contains. But why not only on click on ImageView?

PS:感谢codeMagic:)

PS: Thanks codeMagic :)

编辑:(UPD1)
我创建RemoteViews为:

(UPD1) I create RemoteViews as:

myview = new RemoteViews(packName, R.layout.mywidget); 
Intent svcIntent = new Intent(ctx, WidgetListService.class);
svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME)));
myview.setEmptyView(R.id.widget_email_list, R.id.widget_list_empty_view);
myview.setRemoteAdapter(R.id.widget_email_list, svcIntent);
aAppWidgetManager.updateAppWidget(_widgetId, myview);

我不使用任何的PendingIntent,只设置TextView的文本和隐藏/显示一些看法。同时在logcat中点击是空的。

I don't use any PendingIntent, only set TextView text and hide/show some views. Also logcat on click is empty.

推荐答案

嗯,解决办法很简单。现在我想补充的点击ImageView的(widget_list_overflow)和待发表的意图消失了。

Hm, solution was easy. Now I add pending intent on click ImageView (widget_list_overflow) and issue disappeared.

这篇关于在点击ImageView的非法状态,背景(选择)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆