android-widget

AppWidget Button onClick stops working

早过忘川 提交于 2019-12-12 17:06:40
问题 I have a widget I'm trying to build that consists of only a button. What I'm wanting to do is have the button clicked and then run some simple piece of code (in my test it's a toast alert). It seems to work fine initially, but suddenly the button stops responding to clicks. I've noticed it consistently after the phone has been asleep. Here is my code for the AppWidgetProvider. onUpdate: for (int appWidgetId : appWidgetIds) { RemoteViews remoteView = new RemoteViews(context.getPackageName(), R

setOnTouchListener not called on ViewFlipper

半城伤御伤魂 提交于 2019-12-12 16:06:35
问题 I want to listen to touch events for a viewFlipper. I've been able to listen to touch events in my activity and then modify the viewFlipper but these events are fired wherever the user is within the activity and I need to capture touch events specifically on the viewFlipper. I have tried adding setOnTouchListener but it is not called. I'm assuming the viewFlippers children (webviews) are 'consuming' the touch events. One solution would be to setOnTouchListener's to each of the webviews but

How do I make an EditText raise along with the keyboard when in focus?

孤者浪人 提交于 2019-12-12 16:04:58
问题 Just like in texting applications, I want the keyboard to push the dialog box up when it raises. The issue I'm currently having is that the keyboard actually raises over my dialog box and the screen does not scroll. Here's what I want: (Don't have enough reputation to post images) Image one (Before) Image two (After) See how nicely it raises? How do I go about doing that? 回答1: Use a RelativeLayout and place your EditText using android:layout_alignParentBottom="true" it should then raise

Setting rowcount and column count for grid layout dynamically

烂漫一生 提交于 2019-12-12 14:14:15
问题 I am adding linearlayouts to GridLayout dynamically. I want that to be displayed like grid view. Is it possible to calculate how many linear layouts can be placed in one row and set column count for grid layout or i should use gridview to align them automatically. 回答1: If you want to calculate the column count based on the width of the GridLayout , override the onMeasure method. It provides widthSpec and heightSpec as parameters, from which you can get the actual width and height in pixels

Self-updating every 10 seconds widget Handler.postDelayed problem

不想你离开。 提交于 2019-12-12 14:10:32
问题 I'm trying to make work a self-updating functionality in an Android widget, something simple as changing two TextViews of it every 10 seconds. The ideal solution would be to make it similar to the genie widget (news & weather). And so far, it works okay: it updates every 10 seconds via Handler.postDelayed's Runnable. Runnable updateWidgetText = new Runnable() { @Override public void run() { if (screenEnabled) { AppWidgetManager gm = AppWidgetManager.getInstance(ctx); ComponentName thisWidget

getViewByID Returns null for the Listview

我们两清 提交于 2019-12-12 13:47:22
问题 I have got my main.xml as follows: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:text="TextView" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> <ListView android:layout_height="wrap_content" android:id="@+id/listView1" android:layout_width=

Passing data from widget to app

怎甘沉沦 提交于 2019-12-12 13:08:57
问题 I'm developing a widget for my app and I'd like to pass specific data from the widget to the app. The user can add multiple versions of the widget and I need to detect which widget it is coming from so I can show specific information in the app. What I have works so far, but only if I exit my app completely (repeatedly pressing the back button), otherwise it doesn't seem to be detecting the data being passed in. This the code I have to pass the data from the widget to the app: public class

ListView scroll - one by one

纵饮孤独 提交于 2019-12-12 12:33:29
问题 I have a ListView that must display 4 items at a time. And I must scroll one item, one by one. After user scrolls the ListView, I must readjust the scroll to fit 4 items. I mean, I can´t show an item by half. Another question, is there any way to get the current ListView scrollY offset? Because the listView.getScrollY() method is from View, but not the Scroller object inside the ListView. 回答1: I've found an excellent solution. It works perfect for me. May be my answer will help someone. class

Android ImageSwitcher example

余生颓废 提交于 2019-12-12 12:07:06
问题 Can anyone give me a working example of an ImageSwitcher without a Gallery? Here's my code: ImageSwitcher mImageSwitcher; mImageSwitcher = new ImageSwitcher(this); mImageSwitcher.setLayoutParams(new ImageSwitcher.LayoutParams( LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT)); mImageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in)); mImageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out)); mImageSwitcher.setFactory(this)

how can get text of textview that placed on a widget in android programming

最后都变了- 提交于 2019-12-12 11:10:43
问题 i have a question. i did all things for design and coding a widget before. now i have a button and a textview in my widget. i want when i click on my button my text entered in textview puted as extra for an intent and then start that intent. i can do this with following code in : @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.onUpdate(context, appWidgetManager, appWidgetIds); for (int i=0;i<appWidgetIds.length;i++){ int awID