gpt4 book ai didi

android - 如何将信息查询放入 ListView ?

转载 作者:行者123 更新时间:2023-11-29 02:11:40 27 4
gpt4 key购买 nike

我有一个 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 提要中检索信息查询。这是我如何检索提要的示例。

            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();
}
}

正如您在此处看到的,我检索了一个信息提要...现在,在这种方法中,我想将所有信息设置到一个包含所有信息的列表中。

比如一个有一行的ListView。 row.xml 包含一个 imageView 和一个 TextView。

我将如何着手使每个提要在 ListView 中设置为一行?

编辑:我正在尝试的是通过谷歌使用 gdata api 从搜索中检索视频列表。这是我正在使用的代码..

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。

最佳答案

您需要创建自己的适配器,它应该看起来像这样:

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);

希望这对您有所帮助!

关于android - 如何将信息查询放入 ListView ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6921115/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com