@Override
public void onResponse(final Response response) throws IOException {//okhttp onresponse method
try {
String json = response.body().string();//get data from cinemalytics
Log.v(TAG, json);//
if (response.isSuccessful()) {
mCurrentmovie = getDATA(json);
//mCurrentmovie is an object of Currentmovie getter and setter class.
runOnUiThread(new Runnable() {
@Override
public void run() {
String T = mCurrentmovie.getTitle();
tv.setText(T);
//successfully show in single textview but can't in listview
}
});
} else {
}
} catch (Exception e) {
}
}
});
//返回json对象
private Currentmovie getDATA(String json) throws JSONException {
JSONArray values = new JSONArray(json);
// JSONArray values = object.getJSONArray("0");
// JSONObject ob = object.getJSONObject("0");
JSONObject obj = values.getJSONObject(0);
String Title = obj.getString("Title");
String imgg = obj.getString("PosterPath");
Currentmovie c = new Currentmovie();
c.setImageView(imgg);
Log.e(TAG, Title);
c.setTitle(Title);
return c;
}
//我希望listview图片中的此数据也包含在data.please中,请逐步说明//来自Cinemalytics的json数据
[
{
"Id": "7582268f",
"ImdbId": "tt0979913",
"OriginalTitle": "Life Mein Kabhie Kabhiee",
"Title": "Life Mein Kabhie Kabhiee",
"Description": "",
"TrailerLink": "",
"TrailerEmbedCode": "",
"Country": "IN",
"Region": "BOLLYWOOD",
"Genre": "",
"RatingCount": 1,
"Rating": 2.0,
"CensorRating": "",
"ReleaseDate": "1/1/1900",
"Runtime": 0,
"Budget": 0,
"Revenue": 0,
"PosterPath": "https://s3-ap-southeast-1.amazonaws.com/cinemalytics/movie/70C66638BF359AEA9E9FEE83AE46D18C.jpg"
}
]
// movieAdapter类//在getSystemService中显示错误,其余所有代码都可以…。
package com.example.maau.movieinfo;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;
public class MovieAdapter extends BaseAdapter {
private List<Currentmovie> movieData;
private static LayoutInflater inflater = null;
public MovieAdapter(List<Currentmovie> movieData)
{
this.movieData = movieData;
inflater=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return movieData.size();
}
@Override
public Object getItem(int position) {
return movieData.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
public static class ViewHolder{
public TextView movieTitle;
public ImageView movieImage;
}
public View getView(int position, View convertView, ViewGroup parent)
{
View vi = convertView;
ViewHolder holder;
if(convertView==null){
vi = inflater.inflate(R.layout.row, null);
holder = new ViewHolder();
holder.movieTitle = (TextView) vi.findViewById(R.id.tv);
// holder.movieImage=(ImageView)vi.findViewById(R.id.image);
vi.setTag( holder );
}
else
holder=(ViewHolder)vi.getTag();
holder.movieTitle.setText(movieData.get(position).getTitle());
return vi;
}
}
得到响应后,请遵循以下代码,
首先在所有方法的顶部上方创建以下2个元素。
List<CurrentMovie> moviesList = new ArrayList<>();
MovieAdapter mAdapter;
// Now on response change code as below
if (response.isSuccessful()) {
manageJson(json);
}
public void manageJson(String result)
{
try
{
movieList = new ArrayList<>();
JsonArray jsonArray = new JSONArray(result);
for(int i = 0; i < jsonArray.length(); i++)
{
JSONObject jsonObject = jsonArray.getJsonObject(i);
String Title = obj.getString("Title");
String imgg = obj.getString("PosterPath");
Currentmovie c = new Currentmovie();
c.setImageView(imgg);
c.setTitle(Title);
movieList.add(c);
}
mAdapter = new MovieAdapter(YourActivityName.this, movieList);
listViewObject.setAdapter(mAdapter);
}
catch(Exception e)
{
System.out.println("Error in Result as " + e.toString());
}
}
现在,使用一个适配器在ListView中设置数据
public class MovieAdapter extends BaseAdapter
{
private final Context context;
private List<CurrentMovie> movieData;
private static LayoutInflater inflater=null;
public MovieAdapter(Context context, List<CurrentMovie> movieData)
{
this.context = context;
this.movieData = movieData;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return movieData.size();
}
@Override
public Object getItem(int position) {
return movieData.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
public static class ViewHolder{
public TextView movieTitle;
public ImageView movieImage;
}
public View getView(int position, View convertView, ViewGroup parent)
{
View vi = convertView;
ViewHolder holder;
if(convertView==null){
vi = inflater.inflate(R.layout.tabitem, null);
holder = new ViewHolder();
holder.movieTitle = (TextView) vi.findViewById(R.id.title);
holder.movieImage=(ImageView)vi.findViewById(R.id.image);
vi.setTag( holder );
}
else
holder=(ViewHolder)vi.getTag();
holder.movieTitle.setText(movieData.get(position).getTitle());
return vi;
}
}
在Android应用程序中,我想在AlertDialog中显示自定义列表视图。 我该怎么做呢?
我需要在数据表列中动态显示图像,我在本地文件夹中有图像,如何在Bootsface数据表中这样做? 谢谢你的帮助!
我用于在布局文件中放置一个特殊视图,如文档中所述,以便在没有数据时显示。此视图的id为。
问题内容: 我编写了一个C代码,用于使用libsoup库获取url为“ * http://gdata.youtube.com/feeds/api/standardfeeds/top_rated*”的youtube视频列表。我可以使用libxml2解析返回的xml数据,并从中提取所需的字段。 我想知道如何使用javascript并在浏览器中显示列表。我对javascript有非常基本的了解,但是如果
在我的Spring web MVC应用程序中,我计划在我的jsp视图上显示一些JFree图表,我不知道如何做到这一点,因为我的第一个想法对我不起作用,生成一个图像,然后从文件夹中检索它。 现在我想,控制器能够直接回放图像吗?假设这是我的服务接口: 我可以做这样的事情吗?我如何从我的jsp调用这个映像?