2

I have a created widget and set on click Intent for FrameLayout. Actually I tried for all layouts like LinearLayout, RelativeLayout but no success. I am having a hard time figuring out how to make my app open by click anywhere on widget.

Also i used clickable false for each child of Framelayout. but not sucess :(

<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="4dp">

<FrameLayout
    android:id="@+id/wizFrameLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent">

    <RelativeLayout
        android:id="@+id/wizLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/widget_shape"
        android:clickable="false"
        android:minWidth="110dp"
        android:minHeight="110dp">

        <ListView
            android:id="@+id/wiz_stack_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="0dp"
            android:clickable="false"
            android:divider="@null"
            android:dividerHeight="0dp"
            android:drawSelectorOnTop="false"
            android:listSelector="@android:color/transparent"
            android:padding="0dp" />

        <TextView
            android:id="@+id/wiz_empty_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="No Clock Added" />
    </RelativeLayout>
</FrameLayout>

Here is my Widget Provider code

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    //Toast.makeText(context, "onUpdate", Toast.LENGTH_SHORT).show();
    for (int appWidgetId : appWidgetIds) {
        Intent serviceIntent = new Intent(context, DigitalWidgetService.class);
        serviceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,appWidgetId);
        serviceIntent.setData(Uri.parse(serviceIntent.toUri(Intent.URI_INTENT_SCHEME)));

        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.digital_clock_widget);

        Intent intent = new Intent(context, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
        views.setOnClickPendingIntent(R.id.wizFrameLayout,pendingIntent);

        views.setRemoteAdapter(R.id.wiz_stack_view,serviceIntent);
        views.setEmptyView(R.id.wiz_stack_view,R.id.wiz_empty_view);
        
        appWidgetManager.updateAppWidget(appWidgetId, views);

    }

Widget Item Code for ListView

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextClock
    android:id="@+id/wiz_textClock"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:text="00:00 AM"
    android:textColor="@color/white"
    android:textSize="11dp" />
<TextView
    android:id="@+id/wiz_item_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_toLeftOf="@+id/wiz_textClock"
    android:maxLines="1"
    android:text="item 1"
    android:textColor="@color/white"
    android:textSize="11dp" /></RelativeLayout>

I am attaching snapshot of widget for more clear. Please have a look it.

Widget snapshot

Dev D
  • 37
  • 1
  • 1
  • 3

2 Answers2

0

I think you need to click items on the listview in the listview adapter class

Muhammad Asad
  • 694
  • 6
  • 10
0

I try to do the same: clicking on the whole area of listview or the whole appwidget has to open the app. But I don't know how to implement this. I know about setOnItemClickListener of the listview, but I need the click for the whole area of the listview or whole appwidget. At the moment I've implemented clicking for the main FrameLayout having ListView inside itself, but in such way the click opening the app works everywhere except the listview area...

bic55
  • 83
  • 7
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/31373242) – WhoisAbel Mar 29 '22 at 11:24