Why is Marquee not working in widgets?

I am an android for noob, and I am trying to create a widget that uses a text selection area to display tweets in a ticker. When I set the text in xml, the step label displays correctly in the widgets. However, when I try to set the text programmatically, the selection does not scroll. The text is set, but it just does not scroll. This behavior is bewildering because I used this question as my guide. Any help is appreciated.

My layout

<TextView android:id="@+id/ticker" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:duplicateParentState="true" android:ellipsize="marquee" android:fadingEdge="horizontal" android:focusable="true" android:focusableInTouchMode="true" android:lines="1" android:marqueeRepeatLimit="marquee_forever" android:scrollHorizontally="true" android:text="Simple application that shows how to use marquee, with a long text for Twitter Feed" > //<--this text scrolls fine <requestFocus android:duplicateParentState="true" android:focusable="true" android:focusableInTouchMode="true" /> </TextView> 

My code

 public static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) { //String currentTime = df.format(new Date()); String spotgold = String.valueOf(MyActivity.widgetlivespotgold); String spotsilver = String.valueOf(MyActivity.widgetlivespotsilver); StringBuilder tickertweets=new StringBuilder(); for (int i = 0; i < MyActivity.twittername.size(); i++) { tickertweets.append(MyActivity.twittername.get(i) + ":" + " " + MyActivityActivity.twittertweet.get(i) + " "); } RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.widget1); updateViews.setTextViewText(R.id.goldspot, spotgold); updateViews.setTextViewText(R.id.silverspot, spotsilver); updateViews.setTextViewText(R.id.ticker, tickertweets.toString()); //Text is set, but doesn't scroll appWidgetManager.updateAppWidget(appWidgetId, updateViews); } 
+4
source share
5 answers

I assume this is the following problem:

The setText(CharSequence) method resets the MarqueeRepeatLimit parameter. The setText(CharSequence) method is a RemotableViewMethod , which means you cannot access it from RemoteView. setMarqueeRepeatLimit() does not have this special annotation. I see no way how you can set the text and save your Marquee state inside RemoteView. Maybe the SetText method from TextView will help you a little

 private void setText(CharSequence text, BufferType type, boolean notifyBefore, int oldlen) { if (text == null) { text = ""; } if (!mUserSetTextScaleX) mTextPaint.setTextScaleX(1.0f); if (text instanceof Spanned && ((Spanned) text).getSpanStart(TextUtils.TruncateAt.MARQUEE) >= 0) { setHorizontalFadingEdgeEnabled(true); setEllipsize(TextUtils.TruncateAt.MARQUEE); } int n = mFilters.length; for (int i = 0; i < n; i++) { CharSequence out = mFilters[i].filter(text, 0, text.length(), EMPTY_SPANNED, 0, 0); if (out != null) { text = out; } } if (notifyBefore) { if (mText != null) { oldlen = mText.length(); sendBeforeTextChanged(mText, 0, oldlen, text.length()); } else { sendBeforeTextChanged("", 0, 0, text.length()); } } 
+1
source

Be sure to use android:singleLine="true" and android:scrollHorizontally="false" (or completely remove it) in your XML. That should do the trick.

+1
source

This may work for you.

In your layout:

 <TextView android:id="@+id/TextView03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:marqueeRepeatLimit="marquee_forever" android:text=""/> 

In your code:

 TextView textView = (TextView)findViewById(R.id.TextView03); textView.setText(";lkjdf;alkdsfjoiawejrokajdsl;fkadmnsflkamndvklahoreiuaweifjakldsmflkhfgoueyhtoaijpkjdflkahndsofuhyoeia"); textView.setHorizontallyScrolling(true); textView.setEllipsize(TextUtils.TruncateAt.MARQUEE); textView.setSingleLine(); textView.setSelected(true); 
+1
source

Try it. Before setting the text, set the Marquee spacing.

 SpannableString buffer = new SpannableString(tickertweets.toString()); buffer.setSpan(TextUtils.TruncateAt.MARQUEE,0, (tickertweets.length() -1) ,Spannable.SPAN_INCLUSIVE_INCLUSIVE); updateViews.setTextViewText(R.id.ticker, buffer); 
0
source

You can use this code to scroll text in a textView:

 textView.setEllipsize(TextUtils.TruncateAt.MARQUEE); textView.setSingleLine(); textView.setMarqueeRepeatLimit(10); textView.setFocusable(true); textView.setHorizontallyScrolling(true); textView.setFocusableInTouchMode(true); textView.requestFocus(); 
0
source

All Articles