如何把信息查询到一个ListView? [英] How to put query of information into a listview?
问题描述
我有一个ListView
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>
我从一个URL饲料retreiving的信息的查询。下面是我如何retreive饲料的例子。
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();
}
}
正如你在这里看到我retreive信息的饲料......现在,在这个方法我想设置的所有信息化为保存所有信息的列表。
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.
如用一排一个ListView。而row.xml包含的ImageView和一个TextView。
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?
编辑:什么我试图与使用通过谷歌的API GDATA搜索retreive的视频列表。这里是code我使用..
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: ");
for(String keyword : keywords.getKeywords()) {
System.out.print(keyword + ",");
}
}
}
我想有它与每个视频标题和自己的ImageView为缩略图列表填充。
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();
}
}
和实现它,像这样:
MyCustomAdapter adapter = new MyCustomAdapter(this, R.layout.your_layout, yourObjectArrayList);
ListView list = (ListView)findViewById(R.id.your_list);
list.setAdapter(adapter);
希望这有助于!
这篇关于如何把信息查询到一个ListView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!