I have a ListView
<?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">
<ListView android:layout_height="wrap_content" android:id="@+id/listView1" android:layout_width="match_parent">
</ListView>
</LinearLayout>
I am retreiving a query of information from a URL feed. Here is an example of how i retreive the feed.
query.setOrderBy(YouTubeQuery.OrderBy.VIEW_COUNT);
query.setFullTextQuery("basketball");
query.setSafeSearch(YouTubeQuery.SafeSearch.NONE);
VideoFeed videoFeed = service.query(query, VideoFeed.class);
printVideoFeed(videoFeed, true);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void printVideoFeed(VideoFeed videoFeed, boolean detailed){
videoFeed.getTitle().toString();
}
}
As you see here i retreive a feed of information... Now in this method i would like to set all the information into a list holding all the information.
Such as a ListView with a row. And the row.xml contains a imageView and a TextView.
How would i go about making it so that each feed is set it a row in the list view?
EDIT: What i am trying to is retreive a list of videos from a search using the gdata api through google. Here is the code i am using..
public void printVideoEntry(VideoEntry videoEntry, boolean detailed){
if(detailed){
YouTubeMediaGroup mediaGroup = videoEntry.getMediaGroup();
System.out.println("Uploaded by: " + mediaGroup.getUploader());
//Here i would like to set one of the thumbnails to a imageView.
mediaGroup.getThumbnails();
System.out.println("Video ID: " + mediaGroup.getVideoId());
System.out.println("Description: " +
mediaGroup.getDescription().getPlainTextContent());
MediaPlayer mediaPlayer = mediaGroup.getPlayer();
System.out.println("Web Player URL: " + mediaPlayer.getUrl());
MediaKeywords keywords = mediaGroup.getKeywords();
System.out.print("Keywords: ");
开发者_如何学Gofor(String keyword : keywords.getKeywords()) {
System.out.print(keyword + ",");
}
}
}
I would like to have it populate in a list with each video title and its own imageView for a thumbnail.
You'll want to create your own Adapter, which should look something like this:
public class MyCustomAdapter extends ArrayAdapter<YourObject> {
private final Context mContext;
private final List<YourObject> objectList;
private final int layout;
private final LayoutInflater inflater;
static class ViewHolder {
public ImageView objectImage;
public TextView objectTitle;
}
public MyCustomAdapter(Context context, int layout, List<YourObject> objects) {
super(context, layout, objects);
this.mContext = context;
this.inflater = LayoutInflater.from(context);
this.layout = layout;
this.objectList = objects;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (convertView == null) {
convertView = inflater.inflate(layout, parent, false);
viewHolder = new ViewHolder();
viewHolder.objectImage = (ImageView)convertView.findViewById(R.id.image_id);
viewHolder.objectTitle = (TextView)convertView.findViewById(R.id.title_id);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder)convertView.getTag();
}
viewHolder.objectImage.setImageDrawable(mContext.getResources().getDrawable(R.drawable.your_image))
viewHolder.objectTitle.setText("Title Here");
return convertView;
}
@Override
public int getCount() {
return objectList.size();
}
}
And implement it like so:
MyCustomAdapter adapter = new MyCustomAdapter(this, R.layout.your_layout, yourObjectArrayList);
ListView list = (ListView)findViewById(R.id.your_list);
list.setAdapter(adapter);
Hopefully this helps!
精彩评论