ListVideoActivity
import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.widget.ListView;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.animee.day20.R;
import com.animee.day20.UniteApp;
import java.util.ArrayList;
import java.util.List;
public class ListVideoActivity extends AppCompatActivity {
private ListView mListView;
private VideoListAdapter adapter;
private List<ParseVideoBean.VideoBean>mDatas;
private ProgressDialog dialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_video);
mListView = (ListView) findViewById(R.id.id_lv);
mDatas = new ArrayList<>();
adapter = new VideoListAdapter(this,mDatas);
mListView.setAdapter(adapter);
initDialog();
setData(NetConfig.VIDEO_PATH);
}
private void initDialog(){
dialog = new ProgressDialog(this);
dialog.setMessage("正在加载中.....");
dialog.setTitle("提示信息");
}
private void setData(String url){
dialog.show();
StringRequest request = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String s) {
dialog.dismiss();
if (!TextUtils.isEmpty(s)) {
List<ParseVideoBean.VideoBean>list = ParseVideoBean.parseData(s);
if (list!=null&&list.size()!=0) {
mDatas.addAll(list);
adapter.notifyDataSetChanged();
}
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
dialog.dismiss();
Toast.makeText(ListVideoActivity.this,"网络加载失败,请检查网络!!",Toast.LENGTH_LONG).show();
}
});
UniteApp.getHttpQueue().add(request);
}
}