3

I want to put a textView in homescreen, and I need the marquee effect

public class MainWidget extends AppWidgetProvider {
int a;
RemoteViews remoteViews;
AppWidgetManager appWidgetManager;
ComponentName thisWidget;

String[] s={"woddfdfdfdfdfdffffffffffffffffffffffffffffffff","dd","ddd","ffff"};
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
      int[] appWidgetIds) {
      Timer timer = new Timer();
      timer.scheduleAtFixedRate(new WlanTimer(context, appWidgetManager), 100, 50000);
}

private class WlanTimer extends TimerTask {
        RemoteViews remoteViews;
        AppWidgetManager appWidgetManager;
        ComponentName thisWidget;

public WlanTimer(Context context, AppWidgetManager appWidgetManager) {

        this.appWidgetManager = appWidgetManager;
        remoteViews = new RemoteViews(context.getPackageName(), R.layout.marketwidget_main);
        thisWidget = new ComponentName(context, MainWidget.class);
}

@Override
public void run() {
a=(int) (Math.random()*3);                            
        remoteViews.setTextViewText(R.id.TextView_marketwidget_main_marketmessage,s[a]);
    appWidgetManager.updateAppWidget(thisWidget, remoteViews);
    }
}
}

If i use s[0] instead s[a], it does not run, only "woddfdf" shows up.

My textView xml is:

 <TextView android:id="@+id/TextView_marketwidget_main_marketmessage"
    android:maxLines="1" android:focusable="true"
    android:ellipsize="marquee"
    android:inputType="text"
    android:focusableInTouchMode="true" android:marqueeRepeatLimit="marquee_forever" android:textColor="#ffffff" android:background="@android:color/transparent" android:layout_width="80dip" android:layout_height="20dip"></TextView>
Siddharth
  • 9,349
  • 16
  • 86
  • 148
pengwang
  • 19,536
  • 34
  • 119
  • 168

3 Answers3

5

What I got from your question is, you want to show a scrolling marquee effect in TextView? If I am right, do the following.

Set android:ellipsize="marquee" in TextView element in your layout file (XML). Then, in your Activity's onCreate() method, add the line textView.setSelected(true);.

Note: Replace the name textView with the name of your TextView.

Revert back for any query.

Mudassir
  • 13,031
  • 8
  • 59
  • 87
1

You can set the properties android:ellipsize="marquee" of textview. and hope this link would help you out if on using this property still not working: Ellipsize not working for textView inside custom listView

Community
  • 1
  • 1
Nikki
  • 3,314
  • 13
  • 36
  • 59
0

The minimum code you need to add in xml file is

<TextView
    .
    .
    android:singleLine="true"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    />

also do not forget to add this line in your onCreate method

textview.setSelected(true);
Reza Abedi
  • 419
  • 4
  • 16