如何在app小部件(Remoteviews)中找到孩子的点击位置。

时间:2012-03-27 15:06:24

标签: android android-intent android-widget

我遇到过这个问题。我有一个父线性布局,在水平视图中包含三个子视图。点击特定的孩子时。让我知道点击的子视图的位置。这是Remoteviews中的问题,因为它没有实现onclick事件。

这是主要的xml。

    <LinearLayout
            android:id="@+id/llwidgetlist"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingTop="1dp" >
     </LinearLayout>

此布局包含三个动态

的子项
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
    remoteViews.removeAllViews(R.id.llwidgetlist);
                for(int position=0;position<4;position++){
                    RemoteViews nestedView = widgetGallery.getWidgetHolder(position);
                    remoteViews.addView(R.id.llwidgetlist, nestedView);
                }

child.xml      

 <TextView
            android:id="@+id/ll_widgetplaceholder"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textColor="#787878"
            android:textStyle="bold"
            android:visibility="gone" />
        </LinearLayout>

此子代码..

        Intent intent = new Intent(context, com.indianexpress.android.StoryDescriptionActivity.class);
                intent.putExtra("storylist",storyLists);
                intent.putExtra("position",?);
                PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
                itemViews.setOnClickPendingIntent(R.id.ll_widgetplaceholder, pendingIntent);

让我知道孩子的点击位置。请帮帮我。谢谢。

1 个答案:

答案 0 :(得分:1)

也许您想要做的是调用nestedView.setOnClickPendingIntent,以便将意图附加到一个单独的remoteview子项