从Web服务发送的视频图像

时间:2014-08-16 10:45:25

标签: android image web-services video

我有一个网络服务,可以按名称搜索某些视频。 它传递了视频的名称和图像。 我应该怎么说哪个图像适合哪个视频? 以及我怎么说它才能发挥

package com.video;

import java.util.List;

import android.app.Activity;

import android.os.AsyncTask;

导入android.os.Bundle;

导入android.view.View;

import android.view.View.OnClickListener;

导入android.widget.Button;

导入android.widget.EditText;

导入android.widget.GridView;

import com.uvideo.adapter.VideoSearchAdapter;

import com.uvideo.controller.MasterVideoController;

import com.uvideo.model.VideoSearch;

公共类ActivityVideoSearch扩展了Activity实现OnClickListener {

private VideoSearchAdapter videoSearchAdapter;

private GridView grdVideoList;

private List<VideoSearch> listVideo;

private EditText edtKeySearch;

private Button btnSearch;
// -------------------------
@Override

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.layout_activity_video_search);

    ini();
}
// -------------------------
private void ini() {    

    grdVideoList = (GridView) findViewById(R.id.grdVideoList);

    edtKeySearch = (EditText) findViewById(R.id.edtKeySearch);

    btnSearch = (Button) findViewById(R.id.btnSearchVideo);

    btnSearch.setOnClickListener(this);
}
// -------------------------

private class SearchVideo extends AsyncTask<String, Void, List<VideoSearch>>{

    @Override

    protected List<VideoSearch> doInBackground(String... params) {

        MasterVideoController masterVideoController = new MasterVideoController();

        return masterVideoController.searchVideo(params[0]);                     
    }

    @Override

    protected void onPostExecute(List<VideoSearch> result) {

        super.onPostExecute(result);

        listVideo = result;

        videoSearchAdapter = new VideoSearchAdapter(getBaseContext(),result);

        grdVideoList.setAdapter(videoSearchAdapter);

    }       
}
// -------------------------
@Override

public void onClick(View v) {

    new SearchVideo().execute(edtKeySearch.getText().toString());

}

}

package com.video.adapter;

import java.util.List;

import android.content.Context;

import android.view.LayoutInflater;

导入android.view.View;

import android.view.ViewGroup;

import android.widget.ArrayAdapter;

导入android.widget.TextView;

import com.uvideo.R;

import com.uvideo.model.VideoSearch;

公共类VideoSearchAdapter扩展了ArrayAdapter {

private List<VideoSearch> listVideo;

private Context context;


// ---------------------
public VideoSearchAdapter(Context context,List<VideoSearch> listVideo) {

    super(context, R.layout.row_video_item, listVideo);

    this .listVideo = listVideo;

    this.context = context;
}
// ---------------------
@Override

public int getCount() {

    return super.getCount();
}
// ---------------------

@Override

public VideoSearch getItem(int position) {

    return ((listVideo!=null ? listVideo.get(position):null));
}

// ---------------------
@Override

public View getView(final int position, View convertView, ViewGroup parent) {

    View view = convertView;

    if(view==null){     

        LayoutInflater inflater=(LayoutInflater)

context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        view = inflater.inflate(R.layout.row_video_item, parent,false);

    }

    final VideoSearch video=listVideo.get(position);

    if(video!=null){        

        TextView txtMusicName = (TextView) view.findViewById(R.id.txtVideoName);

        txtMusicName.setTextSize(16);   

        txtMusicName.setText(video.getVideoTitle());    

        // ---------------------

    }

    return view;

}   

// ---------------------

@Override

public long getItemId(int position) {   

    return position;

}

}

package com.video.controller;

import java.util.ArrayList;

import java.util.List;

import org.apache.http.NameValuePair;

import org.apache.http.message.BasicNameValuePair;

import org.json.JSONArray;

import org.json.JSONObject;

import com.uvideo.model.VideoDetail;

import com.uvideo.model.VideoSearch;

import com.uvideo.tools.parser.XmlParser;

import com.uvideo.tools.webservice.WebServiceConnection;

import com.uvideo.tools.webservice.WebServiceConnection2;

public class MasterVideoController扩展了WebServiceConnection {

private String result;

private JSONObject jsonObject;

private JSONArray jsonObjectArray;

private final static String SEARCHKEY="SearchKey";  

// -------------------------

public MasterVideoController() {


}

// -------------------------

public List<VideoDetail> getVideoList(){

    List<NameValuePair> params = new ArrayList<NameValuePair>();

    result = super.sendRequest("MasterVideo", params);

    return getVideoListJson(result);

}

// -------------------------

private List<VideoDetail> getVideoListJson(String json){

    List<VideoDetail> listVideo = new ArrayList<VideoDetail>();

    json = new XmlParser().getxml(json);

    try{

        jsonObject = new JSONObject(json);

            listVideo.add(new VideoDetail(jsonObject.optString(VideoDetail.VIDEOTITLE)

                    , jsonObject.optString(VideoDetail.VIDEOPATH)

                    , jsonObject.optString(VideoDetail.VIDEOIMAGE)

                    , jsonObject.optInt(VideoDetail.VIDEOVISIT)

                    , jsonObject.optString(VideoDetail.CHANNELNAME)

                    , jsonObject.optString(VideoDetail.USERNAME)

                    , jsonObject.optString(VideoDetail.USERIMAGE)

                    , jsonObject.optInt(VideoDetail.USERVIDEOCOUNT)

                    , jsonObject.optInt(VideoDetail.USERFOLLOWER)));
        //} 

        return listVideo;
    }

    catch(Exception exp){   

    }

    return null;

}

// -------------------------

public List<VideoSearch> searchVideo(String requestSearchKey){

    List<NameValuePair> params = new ArrayList<NameValuePair>();

    params.add(new BasicNameValuePair(SEARCHKEY,requestSearchKey)); 

    result = super.sendRequest("SearchByVideoTitle", params);

    return getVideoListSearchJson(result);
}

// -------------------------

private List<VideoSearch> getVideoListSearchJson(String json){

    List<VideoSearch> listVideo = new ArrayList<VideoSearch>();

    json = new XmlParser().getxml(json);

    try{

        jsonObjectArray = new JSONArray(json);

        for (int i = 0; i < jsonObjectArray.length(); i++) {

            jsonObject = (JSONObject) jsonObjectArray.get(i);

            listVideo.add(new VideoSearch(jsonObject.optString(VideoSearch.VIDEOTITLE)

                    , jsonObject.optString(VideoSearch.VIDEOPATH)

                    , jsonObject.optString(VideoSearch.VIDEOIMAGE)

                    , jsonObject.optInt(VideoSearch.VIDEOVISIT) 

                    , jsonObject.optString(VideoSearch.USERNAME)));

        }

        return listVideo;

    }

    catch(Exception exp){

        String a = "";

    }

    return null;

}

// -------------------------

}

package com.video.model;

公共类VideoSearch {

// -------------------------

public final static String VIDEOTITLE="VideoTitle";

public final static String VIDEOPATH="VideoPath";

public final static String VIDEOIMAGE="VideoImage";

public final static String VIDEOVISIT="VideoVisit";

public final static String USERNAME="UserName"; 

// -------------------------

private String videoTitle ;

private String videoPath ;

private String videoImage ;

private int videoVisit ;

private String username ;

// -------------------------

public VideoSearch(String videoTitle , String videoPath ,String videoImage ,int 

videoVisit,String username){

    this.videoTitle = videoTitle;

    this.videoPath = videoPath;

    this.videoImage = videoImage;

    this.videoVisit = videoVisit;

    this.username = username;

}

// -------------------------

public VideoSearch() {


}

// -------------------------

public String getVideoTitle(){

    return videoTitle;

}

public String getvideoPath(){

    return videoPath;

}

public String getVideoImage(){

    return videoImage;

}

public int getVideoVisit(){

    return videoVisit;

}

public String getUsername(){

    return username;

}

// -------------------------

public void setVideoTitle(String videoTitle){

    this.videoTitle = videoTitle;

}

public void setvideoPath(String videoPath){

    this.videoPath = videoPath;

}

public void setVideoImage(String videoImage){

    this.videoImage = videoImage;

}

public void setVideoVisit(int videoVisit){

    this.videoVisit = videoVisit;

}

public void setUsername(String username){

    this.username = username;

}

// -------------------------

}

1 个答案:

答案 0 :(得分:0)

首先,你没有明确说明。 如果您使用的是Web服务,则应通过在Web服务中将它们耦合来发送项目。 就像在JSON中一样

{ 视频[{&#34;名称&#34;:&#34; ABC&#34;&#34; IMAGE_URL&#34;:&#34; kvndskk&#34;} {&#34;名称&#34;:& #34; ABC&#34;&#34; IMAGE_URL&#34;:&#34; kvndskk&#34;} {&#34;名称&#34;:&#34; ABC&#34;&#34; IMAGE_URL& #34;:&#34; kvndskk&#34;} {&#34;名称&#34;:&#34; ABC&#34;&#34; IMAGE_URL&#34;:&#34; kvndskk&#34;} ] }

在这里,你看到你收到了一对