I have a list of items i retrieve from html.
They are all titles.
What i am doing is testing each title for a specific thing..
If it has it i want to add it to a TextView in a widget.
The only problem is that if they are more than 1 item the widget wont hold all of the items.
and listview layout isnt supported in widgets older than 3.0.
SO how can i add each item to its on TextView and then display each item using a next button to show the next textview?
EDIT:
Okay that SOunds like it makes sense. SO here how i retrieve my titles...
What would you recommend as far as setting them to a ArrayList and showing the next item in the list when the textview is clicked?
while(doc == null && retry < 5){
retry++;
try {
doc = Jsoup.connect(site).get();
} catch (IOException e) {
Log.e("Html", "JSoup get retrieved no document", e);
}
}
if(doc != null){
title = d开发者_如何学编程oc.select("tr> td.indexList1, tr > td.indexList2");
if(title != null){
// Iterator over those elements
ListIterator<Element> postIt = title.listIterator();
//Loads all the items until there is no .hasNExt()
while (postIt.hasNext()) {
// Add the game text to the ArrayList
Element name = postIt.next();
nameString = name.text();
list.add(new Release(nameString));
So how would i use this to set a textview initially, and then( with the code you suggested) allow the next item in the list to be loaded into a text view?
Keep titles in a list (java list, like ArrayList for example) and have only 1 textview defined in your layout.
In your manifest add a new intent filter to your widgetprovider (reciever) for example:
<intent-filter>
<action android:name="WIDGET_NEXT_TITLE" />
</intent-filter>
And in your widget provider class add an onClickPendingIntent to your textview:
final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
final Intent nextTitleIntent = new Intent("WIDGET_NEXT_TITLE");
nextTitleIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, nextTitleIntent, PendingIntent.FLAG_UPDATE_CURRENT);
views.setOnClickPendingIntent(R.id.textview_id, pendingIntent);
You can do it in your onUpdate method for example. Now on every click and intent will be fired and all you need is to catch it and set the next title in a textview. In your widgetprovider override method onRecieve like this:
if ("WIDGET_NEXT_TITLE".equals(intent.getAction())) {
final int widgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
if (widgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
// get the next title here and set the text in a textview through RemoteView
}
} else {
super.onReceive(context, intent);
}
Something like that. Of course it's very simplified, since you need to keep the track of the currently displayed title, but I hope you get the idea.
精彩评论