'Start activity by clicking on whole Widget is not working in Android Studio
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.
Solution 1:[1]
I think you need to click items on the listview in the listview adapter class
Solution 2:[2]
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...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Muhammad Asad |
| Solution 2 | bic55 |

