- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在开发一个 Android 主屏幕应用小部件,它使用自定义行布局填充 ListView 。 ListView 已正确填充,但当我单击任何项目时,没有任何反应。
这里是一些相关的部分
来自 AppWidgetManager 的 onUpdate()
...
final Intent contactIntent = new Intent(context, ContactService.class);
contactIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
contactIntent.setData(Uri.parse(contactIntent.toUri(Intent.URI_INTENT_SCHEME)));
view.setRemoteAdapter(widgetId, R.id.listview, contactIntent);
//works fine up to here, populates ListView
//Set up pendingIntentTemplate
final Intent contactClick = new Intent(context,ContactDial.class);
contactClick.setData(Uri.parse(contactClick.toUri(Intent.URI_INTENT_SCHEME)));
final PendingIntent contactClickPI = PendingIntent.getBroadcast(context,
0,contactClick,PendingIntent.FLAG_UPDATE_CURRENT);
view.setPendingIntentTemplate(R.id.listview, contactClickPI);
Log.d("TEMPLATE", "set template");
...
来自 RemoteViewsFactory 的 getViewAt(int position)
final Intent i = new Intent();
final Bundle extra = new Bundle();
extra.putString("number", phoneNumber);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtras(extra);
row.setOnClickFillInIntent(R.id.contact_row,i);
Log.d("FACTORY", "Set Intent Template");
日志显示代码已正确执行,但出于某种原因它似乎没有记录我的点击。我在应该将 Intent 发送到的类的 onCreate 中放置了一个 Log.d,但它从未发生过。以下是我的布局的重要部分。
主要布局:
<LinearLayout
android:id="@+id/layout_two"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants" >
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="260dp" />
<!-- Some other views -->
</LinearLayout>
自定义行:
<LinearLayout android:id="@+id/contact_row"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:background="@xml/buttoncolor_selector"
android:paddingBottom="2dp"
android:layout_height="?android:attr/listPreferredItemHeight"
android:paddingLeft="10dip" >
<ImageView
android:id="@+id/contact_photo"
android:layout_width="@android:dimen/notification_large_icon_width"
android:layout_height="match_parent"
android:layout_marginRight="5dip"
android:src="@drawable/ic_action_person />
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
<TextView
android:id="@+id/contact_name"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:textSize="18sp"
android:gravity="center_vertical"
android:singleLine="true"
android:ellipsize="marquee"
android:textIsSelectable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"/>
<TextView
android:id="@+id/contact_number"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:singleLine="true"
android:ellipsize="marquee"
android:textIsSelectable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false" />
</LinearLayout>
</LinearLayout>
我几乎查看了在 Internet 上可以找到的每个示例,但没有一个解决方案有任何改变。请帮忙。
最佳答案
在您的自定义行中,尝试将 android:id="@+id/contact_row"
向下移动到一个 subview (即使它是一个“无用”的 View 组,只是围绕着其他所有内容)。或者,用 FrameLayout 围绕您的顶级 LinearLayout。我没有运气将 setOnClickFillInIntent() 设置为像那样在最顶层的 View 组上定位 ID。
像这样,
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout android:id="@+id/contact_row"
android:orientation="horizontal"
android:layout_width="match_parent"
android:background="@xml/buttoncolor_selector"
android:paddingBottom="2dp"
android:layout_height="?android:attr/listPreferredItemHeight"
android:paddingLeft="10dip" >
<ImageView
android:id="@+id/contact_photo"
android:layout_width="@android:dimen/notification_large_icon_width"
android:layout_height="match_parent"
android:layout_marginRight="5dip"
android:src="@drawable/ic_action_person" />
........
根据您的需要,如果您重新安排您的布局,您也许可以吃蛋糕并拥有它,并且拥有一个无用的 View 组。
关于android - 使用 setOnClickFillInIntent 和 setPendingIntentTemplate 时,不会发生点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24944022/
我正在做一个带有一个 stackView 的小部件,我正在使用 RemoteViewFactory 在其中添加位图(图像)。 我的问题是当我想为每个图像(我在 stackView 中)执行 onCli
我正在将应用小部件中的 ListView 更改为 AdapterViewFlipper。问题是,我需要处理一个项目的点击。使用 setPendingIntentTemplate() 将挂起的 Inte
我正在开发一个 Android 主屏幕应用小部件,它使用自定义行布局填充 ListView 。 ListView 已正确填充,但当我单击任何项目时,没有任何反应。 这里是一些相关的部分 来自 Ap
我是一名优秀的程序员,十分优秀!