【发布时间】:2019-06-14 09:38:58
【问题描述】:
我想通过单击从 ListView 中获取电影标题。我得到的数据来自 api,由改造提供。目前,我正在尝试使用这个界面
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String s = String.valueOf(listView.getItemAtPosition(position));
Toast.makeText(genres_listView.this,s,Toast.LENGTH_LONG).show();
}
});
但是我得到了一些奇怪的值,比如
com.example.myfilmguide.models.itemList_model$itemList_Results@21f3fae
我应该如何正确编码,以获得正常的标题?
@编辑
这是你们想要的 POJO 类。
public class itemList_model {
@SerializedName("total_results")
private int total_results;
@SerializedName("results")
private List<itemList_Results> results;
public List<itemList_Results> getResults() {
return results;
}
public int getTotal_results() {
return total_results;
}
public class itemList_Results{
@SerializedName("name")
String name;
@SerializedName("title")
String title;
@SerializedName("vote_average")
Double vote;
@SerializedName("overview")
String overview;
@SerializedName("release_date")
String releaseDate;
@SerializedName("id")
int id;
public itemList_Results(String title, Double vote, String releaseDate, String overview) {
this.title = title;
this.vote = vote;
this.releaseDate = releaseDate;
this.overview = overview;
}
public String getTitle() {
return title;
}
public Double getVote() {
return vote;
}
public String getReleaseDate() {
return releaseDate;
}
public String getOverview() {
return overview;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
}
【问题讨论】:
-
覆盖模型的字符串方法..
-
getItemAtPosition(int position) 将为您提供您在 listView 中添加的对象。
-
发布您在 listView 中添加的模型
-
显示你的模型类
-
我只是编辑了问题。
标签: java android retrofit themoviedb-api