Reputation: 19956
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>
Upvotes: 3
Views: 8404
Reputation: 448
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);
Upvotes: 0
Reputation: 3318
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
Upvotes: 1
Reputation: 13174
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.
Upvotes: 5