布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="@+id/pager"></android.support.v4.view.ViewPager>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/radiogroup"
android:orientation="horizontal"
android:gravity="center">
<RadioButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/r1"
android:gravity="center"
android:drawableTop="@drawable/sel"
android:text="快手"
android:button="@null"/>
<RadioButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/r2"
android:gravity="center"
android:drawableTop="@drawable/sel"
android:text="抖音"
android:button="@null"/>
</RadioGroup>
</LinearLayout>
滑动页面
package com.bawei.week1;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioGroup;
import com.bawei.week1.adapter.MyAdapter;
import com.bawei.week1.frag.Frag1;
import com.bawei.week1.frag.Frag2;
import java.util.ArrayList;
public class MainActivity extends FragmentActivity {
private ViewPager pager;
private RadioGroup radiogroup;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pager = findViewById(R.id.pager);
radiogroup = findViewById(R.id.radiogroup);
ArrayList<Fragment> list = new ArrayList<>();
list.add(new Frag1());
list.add(new Frag2());
MyAdapter adapter = new MyAdapter(getSupportFragmentManager(), list);
pager.setAdapter(adapter);
radiogroup.check(radiogroup.getChildAt(0).getId());
pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int i, float v, int i1) {
}
@Override
public void onPageSelected(int i) {
radiogroup.check(radiogroup.getChildAt(i).getId());
}
@Override
public void onPageScrollStateChanged(int i) {
}
});
radiogroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId){
case R.id.r1:
pager.setCurrentItem(0);
break;
case R.id.r2:
pager.setCurrentItem(1);
break;
}
}
});
}
}
Adapter
package com.bawei.week1.adapter;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import java.util.ArrayList;
/**
* @Auther: 孙鹏飞
* @Date: 2019/2/16 09:43:05
* @Description:
*/
public class MyAdapter extends FragmentPagerAdapter {
private ArrayList<Fragment>list;
public MyAdapter(FragmentManager fm, ArrayList<Fragment> list) {
super(fm);
this.list = list;
}
@Override
public Fragment getItem(int i) {
return list.get(i);
}
@Override
public int getCount() {
return list.size();
}
}
frag1布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listview"></ListView>
</android.support.constraint.ConstraintLayout>
frag2布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="300dp"
android:layout_height="300dp"
android:id="@+id/image1"/>
</android.support.constraint.ConstraintLayout>
http
package com.bawei.week1.http;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
/**
* @Auther: 孙鹏飞
* @Date: 2019/2/16 09:48:35
* @Description:
*/
public class Http {
//判断网络
public static boolean isConnectionWork(Context context){
if(context!=null){
//连接管理器
ConnectivityManager systemService = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
//判断网络状态
NetworkInfo info = systemService.getActiveNetworkInfo();
if(info!=null){
return info.isConnected();
}
}
return false;
}
//get请求
public static String requestget(String s){
try {
//设置url
URL url = new URL(s);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(5000);
connection.setReadTimeout(5000);
//请求码
int code = connection.getResponseCode();
if(code==200){
//获取数据
InputStream stream = connection.getInputStream();
//缓冲流
BufferedReader reader = new BufferedReader(new InputStreamReader(stream,"utf-8"));
//拼接字符串
StringBuffer buffer = new StringBuffer();
String str="";
while ((str=reader.readLine())!=null){
buffer.append(str);
}
return buffer.toString();
}
connection.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static Bitmap pic(String s){
try {
//设置url
URL url = new URL(s);
HttpURLConnection connection1 = (HttpURLConnection) url.openConnection();
connection1.setRequestMethod("GET");
connection1.setConnectTimeout(5000);
connection1.setReadTimeout(5000);
//请求码
int code = connection1.getResponseCode();
if(code==200){
//获取数据
InputStream stream1 = connection1.getInputStream();
Bitmap bitmap = BitmapFactory.decodeStream(stream1);
return bitmap;
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
AsncyTask
package com.bawei.week1.aysnctask;
import android.os.AsyncTask;
import com.bawei.week1.http.Http;
/**
* @Auther: 孙鹏飞
* @Date: 2019/2/16 10:29:54
* @Description:
*/
public class MyAsyncTask extends AsyncTask <String,Integer,String>{
@Override
//子线程
protected String doInBackground(String... strings) {
return Http.requestget(strings[0]);
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
ca.getData(s);
}
//接口回调
//创建接口
public interface Call{
//抽象方法
String getData(String s);
}
//属性
private Call ca;
public void setCa(Call ca) {
this.ca = ca;
}
}
jsonbean
package com.bawei.week1.bean;
import java.util.List;
/**
* @Auther: 孙鹏飞
* @Date: 2019/2/16 10:52:17
* @Description:
*/
public class JsonBean {
/**
* code : 200
* message : 成功!
* result : [{"pic_s210":"http://business.cdn.qianqian.com/qianqian/pic/bos_client_734232335ef76f5a05179797875817f3.jpg","bg_pic":"http://business0.qianqian.com/qianqian/file/5bfe4e9aa7496_218.png","color":"0xDC5900","pic_s444":"http://hiphotos.qianqian.com/ting/pic/item/c83d70cf3bc79f3d98ca8e36b8a1cd11728b2988.jpg","count":4,"type":2,"content":[{"all_rate":"96,128,224,320,flac","song_id":"611238837","rank_change":"0","biaoshi":"lossless,vip,perm-3","author":"陈柯宇","album_id":"611238835","pic_small":"http://qukufile2.qianqian.com/data2/pic/2d5ab3120f08727becfc2803ee5402f7/611740447/611740447.jpg@s_1,w_90,h_90","title":"生僻字","pic_big":"http://qukufile2.qianqian.com/data2/pic/2d5ab3120f08727becfc2803ee5402f7/611740447/611740447.jpg@s_1,w_150,h_150","album_title":"生僻字"},{"all_rate":"96,128,224,320,flac","song_id":"606149060","rank_change":"0","biaoshi":"lossless,perm-1","author":"展展与罗罗","album_id":"606149057","pic_small":"http://qukufile2.qianqian.com/data2/pic/c9aa6f85bf036735c355a05dd373ff0b/606149058/606149058.png@s_1,w_90,h_90","title":"沙漠骆驼","pic_big":"http://qukufile2.qianqian.com/data2/pic/c9aa6f85bf036735c355a05dd373ff0b/606149058/606149058.png@s_1,w_150,h_150","album_title":"沙漠骆驼"},{"all_rate":"96,128,224,320,flac","song_id":"604568155","rank_change":"0","biaoshi":"lossless,vip,perm-1","author":"马良,孙茜茹","album_id":"604568152","pic_small":"http://qukufile2.qianqian.com/data2/pic/f53a667bbf3c11df1da0841fd34c4d9d/604568153/604568153.jpg@s_1,w_90,h_90","title":"往后余生","pic_big":"http://qukufile2.qianqian.com/data2/pic/f53a667bbf3c11df1da0841fd34c4d9d/604568153/604568153.jpg@s_1,w_150,h_150","album_title":"往后余生"},{"all_rate":"96,128,224,320,flac","song_id":"598740690","rank_change":"0","biaoshi":"lossless,perm-3","author":"张杰,张碧晨","album_id":"598740686","pic_small":"http://qukufile2.qianqian.com/data2/pic/2854c6d30aab478cec599a174c911eea/598740687/598740687.jpg@s_1,w_90,h_90","title":"只要平凡","pic_big":"http://qukufile2.qianqian.com/data2/pic/2854c6d30aab478cec599a174c911eea/598740687/598740687.jpg@s_1,w_150,h_150","album_title":"只要平凡"}],"bg_color":"0xFBEFE6","web_url":"","name":"热歌榜","comment":"该榜单是根据千千音乐平台歌曲每周播放量自动生成的数据榜单,统计范围为千千音乐平台上的全部歌曲,每日更新一次","pic_s192":"http://business.cdn.qianqian.com/qianqian/pic/bos_client_1452f36a8dc430ccdb8f6e57be6df2ee.jpg","pic_s260":"http://hiphotos.qianqian.com/ting/pic/item/838ba61ea8d3fd1f1326c83c324e251f95ca5f8c.jpg"},{"pic_s210":"http://business.cdn.qianqian.com/qianqian/pic/bos_client_dea655f4be544132fb0b5899f063d82e.jpg","bg_pic":"http://business0.qianqian.com/qianqian/file/5c3d586d234b4_292.png","color":"0x5B9400","pic_s444":"http://hiphotos.qianqian.com/ting/pic/item/78310a55b319ebc4845c84eb8026cffc1e17169f.jpg","count":4,"type":1,"content":[{"all_rate":"96,128,224,320,flac","song_id":"612368947","rank_change":"0","biaoshi":"first,lossless,perm-1","author":"周笔畅","album_id":"612368945","pic_small":"http://qukufile2.qianqian.com/data2/pic/8cefae6be35b7bed624b39bfe0f245a7/612369158/612369158.jpg@s_1,w_90,h_90","title":"去流浪(电影《流浪地球》推广曲)","pic_big":"http://qukufile2.qianqian.com/data2/pic/8cefae6be35b7bed624b39bfe0f245a7/612369158/612369158.jpg@s_1,w_150,h_150","album_title":"去流浪(电影《流浪地球》推广曲)"},{"all_rate":"96,128,224,320,flac","song_id":"612135964","rank_change":"0","biaoshi":"first,lossless,vip,perm-1","author":"刘珂矣","album_id":"612135962","pic_small":"http://qukufile2.qianqian.com/data2/pic/93e6097740fed31485251952d5cb26ea/612146894/612146894.jpg@s_1,w_90,h_90","title":"半壶纱(电视剧《小女花不弃》插曲)","pic_big":"http://qukufile2.qianqian.com/data2/pic/93e6097740fed31485251952d5cb26ea/612146894/612146894.jpg@s_1,w_150,h_150","album_title":"半壶纱"},{"all_rate":"96,128,224,320,flac","song_id":"612313835","rank_change":"0","biaoshi":"first,lossless,perm-3","author":"沈腾","album_id":"612313833","pic_small":"http://qukufile2.qianqian.com/data2/pic/841c14e63a26b6d6cdc68400047b9ebe/612314830/612314830.jpg@s_1,w_90,h_90","title":"平凡之路(电影《飞驰人生》特别版)","pic_big":"http://qukufile2.qianqian.com/data2/pic/841c14e63a26b6d6cdc68400047b9ebe/612314830/612314830.jpg@s_1,w_150,h_150","album_title":"平凡之路(电影《飞驰人生》特别版)"},{"all_rate":"96,128,224,320,flac","song_id":"612387139","rank_change":"3","biaoshi":"first,lossless,perm-1","author":"韩寒","album_id":"612387137","pic_small":"http://qukufile2.qianqian.com/data2/pic/cd58b811b510d0b36193056d3b57a2b1/612387156/612387156.jpg@s_1,w_90,h_90","title":"奉献(电影《飞驰人生》片尾曲)","pic_big":"http://qukufile2.qianqian.com/data2/pic/cd58b811b510d0b36193056d3b57a2b1/612387156/612387156.jpg@s_1,w_150,h_150","album_title":"奉献"}],"bg_color":"0xEFF5E6","web_url":"","name":"新歌榜","comment":"该榜单是根据千千音乐平台歌曲每日播放量自动生成的数据榜单,统计范围为近期发行的歌曲,每日更新一次","pic_s192":"http://business.cdn.qianqian.com/qianqian/pic/bos_client_9a4fbbbfa50203aaa9e69bf189c6a45b.jpg","pic_s260":"http://hiphotos.qianqian.com/ting/pic/item/e850352ac65c1038cb0f3cb0b0119313b07e894b.jpg"},{"pic_s210":"http://business.cdn.qianqian.com/qianqian/pic/bos_client_e58a5196bcd49d77d4a099b60b0bc03b.jpg","bg_pic":"http://business0.qianqian.com/qianqian/file/5bfe4eacbcea8_225.png","color":"0x21BFA6","pic_s444":"http://hiphotos.qianqian.com/ting/pic/item/738b4710b912c8fca95d9ecbfe039245d688210d.jpg","count":4,"type":25,"content":[{"all_rate":"96,128,224,320,flac","song_id":"602980311","rank_change":"0","biaoshi":"lossless,perm-3","author":"龙梅子,王娜","album_id":"602980305","pic_small":"http://qukufile2.qianqian.com/data2/pic/015c6c99e1ced5261f624ef20cd7912f/609142152/609142152.jpg@s_1,w_90,h_90","title":"至少还有你爱我","pic_big":"http://qukufile2.qianqian.com/data2/pic/015c6c99e1ced5261f624ef20cd7912f/609142152/609142152.jpg@s_1,w_150,h_150","album_title":"至少还有你爱我"},{"all_rate":"96,128,224,320,flac","song_id":"611717057","rank_change":"0","biaoshi":"lossless,perm-1","author":"龙梅子","album_id":"611717054","pic_small":"http://qukufile2.qianqian.com/data2/pic/3e6581f50cac570485718a4d7473fc13/611718813/611718813.jpg@s_1,w_90,h_90","title":"缘为冰","pic_big":"http://qukufile2.qianqian.com/data2/pic/3e6581f50cac570485718a4d7473fc13/611718813/611718813.jpg@s_1,w_150,h_150","album_title":"缘为冰"},{"all_rate":"96,128,224,320,flac","song_id":"601914158","rank_change":"0","biaoshi":"lossless,perm-3","author":"龙梅子,老猫","album_id":"601914154","pic_small":"http://qukufile2.qianqian.com/data2/pic/e3feb8c1acbc7680dab69f244413bc49/601914155/601914155.jpg@s_1,w_90,h_90","title":"都说","pic_big":"http://qukufile2.qianqian.com/data2/pic/e3feb8c1acbc7680dab69f244413bc49/601914155/601914155.jpg@s_1,w_150,h_150","album_title":"都说"},{"all_rate":"96,128,224,320,flac","song_id":"604383128","rank_change":"0","biaoshi":"lossless,perm-3","author":"龙梅子,冷漠","album_id":"604383123","pic_small":"http://qukufile2.qianqian.com/data2/pic/0201315b2edd9a7ab54b2244d801ba46/604383124/604383124.jpg@s_1,w_90,h_90","title":"唱一首情歌","pic_big":"http://qukufile2.qianqian.com/data2/pic/0201315b2edd9a7ab54b2244d801ba46/604383124/604383124.jpg@s_1,w_150,h_150","album_title":"唱一首情歌"}],"bg_color":"0xE9F9F6","web_url":"","name":"网络歌曲榜","comment":"实时展现千千音乐最热门网络歌曲排行","pic_s192":"http://business.cdn.qianqian.com/qianqian/pic/bos_client_6b67628d46638bccdc6bd8c9854b759b.jpg","pic_s260":"http://hiphotos.qianqian.com/ting/pic/item/6c224f4a20a44623d567cd649a22720e0cf3d703.jpg"},{"pic_s210":"http://business.cdn.qianqian.com/qianqian/pic/bos_client_4de71fefad5f1fdb0a90b3c51b5a6f97.jpg","bg_pic":"http://business0.qianqian.com/qianqian/file/5bfe4ed160c12_921.png","color":"0x967456","pic_s444":"http://hiphotos.qianqian.com/ting/pic/item/f703738da97739121a5aed67fa198618367ae2bc.jpg","count":4,"type":24,"content":[{"all_rate":"96,128,224,320","song_id":"34190723","rank_change":"0","biaoshi":"perm-1","author":"敬善媛","album_id":"34191191","pic_small":"http://qukufile2.qianqian.com/data2/pic/f37a3c22e4885f25bbe81ac97ae8ca26/611766801/611766801.jpg@s_1,w_90,h_90","title":"大悲咒","pic_big":"http://qukufile2.qianqian.com/data2/pic/f37a3c22e4885f25bbe81ac97ae8ca26/611766801/611766801.jpg@s_1,w_150,h_150","album_title":"如来云水月"},{"all_rate":"96,128,224,320,flac","song_id":"257535276","rank_change":"0","biaoshi":"lossless,perm-3","author":"贾乃亮,贾云馨","album_id":"260368616","pic_small":"http://qukufile2.qianqian.com/data2/pic/260368391/260368391.jpg@s_1,w_90,h_90","title":"大王叫我来巡山","pic_big":"http://qukufile2.qianqian.com/data2/pic/260368391/260368391.jpg@s_1,w_150,h_150","album_title":"万万没想到 电影原声带"},{"all_rate":"96,128,224,320,flac","song_id":"261498824","rank_change":"0","biaoshi":"lossless,perm-3","author":"邓超","album_id":"261498722","pic_small":"http://qukufile2.qianqian.com/data2/pic/261498695/261498695.jpg@s_0,w_90","title":"无敌","pic_big":"http://qukufile2.qianqian.com/data2/pic/261498695/261498695.jpg@s_0,w_150","album_title":"无敌"},{"all_rate":"96,128,224,320,flac","song_id":"260375666","rank_change":"1","biaoshi":"lossless,vip,perm-3","author":"崔子格","album_id":"260375703","pic_small":"http://qukufile2.qianqian.com/data2/pic/3fdeac31e0fa76a2bc87580bc1ad6b1c/610777743/610777743.jpg@s_1,w_90,h_90","title":"可念不可说","pic_big":"http://qukufile2.qianqian.com/data2/pic/3fdeac31e0fa76a2bc87580bc1ad6b1c/610777743/610777743.jpg@s_1,w_150,h_150","album_title":"太子妃升职记 网剧原声带"}],"bg_color":"0xF5F1EE","web_url":"","name":"影视金曲榜","comment":"实时展现千千音乐最热门影视歌曲排行","pic_s192":"http://business.cdn.qianqian.com/qianqian/pic/bos_client_2347fb14878de20a3b972a8f44a5c3a8.jpg","pic_s260":"http://hiphotos.qianqian.com/ting/pic/item/9f2f070828381f3052bae5afab014c086e06f011.jpg"},{"pic_s210":"http://business.cdn.qianqian.com/qianqian/pic/bos_client_ecd2c13c57fb27574b9e758e4f707cef.jpg","bg_pic":"http://business0.qianqian.com/qianqian/file/5bfe4e5a1364a_423.png","color":"0xD98E26","pic_s444":"http://hiphotos.qianqian.com/ting/pic/item/6f061d950a7b0208b85e57e760d9f2d3572cc825.jpg","count":4,"type":22,"content":[{"all_rate":"96,128,224,320,flac","song_id":"790142","rank_change":"0","biaoshi":"lossless,perm-3","author":"刘若英","album_id":"190892","pic_small":"http://qukufile2.qianqian.com/data2/pic/51677db1f7b51f1f1bacd1a2498665ff/190892/190892.jpg@s_1,w_90,h_90","title":"后来","pic_big":"http://qukufile2.qianqian.com/data2/pic/51677db1f7b51f1f1bacd1a2498665ff/190892/190892.jpg@s_1,w_150,h_150","album_title":"我等你"},{"all_rate":"96,128,224,320,flac","song_id":"931434","rank_change":"0","biaoshi":"lossless,perm-3","author":"周华健","album_id":"194037","pic_small":"http://qukufile2.qianqian.com/data2/pic/c9291324603915130fd366e4e94cc237/194037/194037.jpg@s_1,w_90,h_90","title":"风雨无阻","pic_big":"http://qukufile2.qianqian.com/data2/pic/c9291324603915130fd366e4e94cc237/194037/194037.jpg@s_1,w_150,h_150","album_title":"风雨无阻"},{"all_rate":"64,96,128,224,320,flac","song_id":"312707","rank_change":"0","biaoshi":"lossless,perm-3","author":"张国荣","album_id":"64742","pic_small":"http://qukufile2.qianqian.com/data2/pic/2037fc888a8f4d84c6fcb62c9536cebd/583717040/583717040.jpg@s_1,w_90,h_90","title":"当爱已成往事","pic_big":"http://qukufile2.qianqian.com/data2/pic/2037fc888a8f4d84c6fcb62c9536cebd/583717040/583717040.jpg@s_1,w_150,h_150","album_title":"宠爱"},{"all_rate":"96,128,224,320,flac","song_id":"704195","rank_change":"0","biaoshi":"lossless,perm-3","author":"任贤齐","album_id":"173971","pic_small":"http://qukufile2.qianqian.com/data2/pic/73a3804e1b971cbebc63d99260278136/173971/173971.jpg@s_1,w_90,h_90","title":"伤心太平洋","pic_big":"http://qukufile2.qianqian.com/data2/pic/73a3804e1b971cbebc63d99260278136/173971/173971.jpg@s_1,w_150,h_150","album_title":"情义"}],"bg_color":"0xFBF4EA","web_url":"","name":"经典老歌榜","comment":"实时展现千千音乐最热门经典老歌排行","pic_s192":"http://business.cdn.qianqian.com/qianqian/pic/bos_client_e6b795613995b69b73861ca7e7732015.jpg","pic_s260":"http://hiphotos.qianqian.com/ting/pic/item/0bd162d9f2d3572cd909f4da8813632763d0c3c9.jpg"},{"pic_s210":"http://business.cdn.qianqian.com/qianqian/pic/bos_client_ad19dd0cd653dbf9b2fca05b5ae6f87f.jpg","bg_pic":"http://business0.qianqian.com/qianqian/file/5bfe4e726acbc_309.png","color":"0x4A90E2","pic_s444":"http://hiphotos.qianqian.com/ting/pic/item/8d5494eef01f3a291bf6bec89b25bc315c607cfd.jpg","count":4,"type":21,"content":[{"all_rate":"96,128,224,320,flac","song_id":"573313333","rank_change":"0","biaoshi":"lossless,perm-1","author":"Maksim","album_id":"573313330","pic_small":"http://qukufile2.qianqian.com/data2/pic/d5dee954c872320a210a326180425cfc/591310208/591310208.jpg@s_1,w_90,h_90","title":"New Silk Road","pic_big":"http://qukufile2.qianqian.com/data2/pic/d5dee954c872320a210a326180425cfc/591310208/591310208.jpg@s_1,w_150,h_150","album_title":"New Silk Road"},{"all_rate":"96,128,224,320,flac","song_id":"590762992","rank_change":"0","biaoshi":"lossless,perm-1","author":"Vitas","album_id":"590762988","pic_small":"http://qukufile2.qianqian.com/data2/pic/4d475c81e4c562301e21c2d102165205/590761655/590761655.jpg@s_1,w_90,h_90","title":"Симфония № 4(交响乐4号)","pic_big":"http://qukufile2.qianqian.com/data2/pic/4d475c81e4c562301e21c2d102165205/590761655/590761655.jpg@s_1,w_150,h_150","album_title":"20"},{"all_rate":"96,128,224,320","song_id":"65626244","rank_change":"0","biaoshi":"perm-1","author":"弗雷德乐队","album_id":"65626242","pic_small":"http://qukufile2.qianqian.com/data2/pic/88411609/88411609.jpg@s_1,w_90,h_90","title":"因为爱情 (法语版)","pic_big":"http://qukufile2.qianqian.com/data2/pic/88411609/88411609.jpg@s_1,w_150,h_150","album_title":"致青春 (法语版)"},{"all_rate":"96,128,224,320,flac","song_id":"588688244","rank_change":"0","biaoshi":"lossless,vip,perm-1","author":"I WEAR* EXPERIMENT乐队","album_id":"588688241","pic_small":"http://qukufile2.qianqian.com/data2/pic/3aa6422af908cf869262f9c75f3c3530/588688242/588688242.jpg@s_1,w_90,h_90","title":"Dogs","pic_big":"http://qukufile2.qianqian.com/data2/pic/3aa6422af908cf869262f9c75f3c3530/588688242/588688242.jpg@s_1,w_150,h_150","album_title":"Dogs"}],"bg_color":"0xEDF4FC","web_url":"","name":"欧美金曲榜","comment":"实时展现千千音乐最热门欧美歌曲排行","pic_s192":"http://business.cdn.qianqian.com/qianqian/pic/bos_client_9362a5a55277e6fb271010a45bc99e17.jpg","pic_s260":"http://hiphotos.qianqian.com/ting/pic/item/8b13632762d0f7035cb3feda0afa513d2697c5b7.jpg"}]
*/
private int code;
private String message;
private List<ResultBean> result;
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public List<ResultBean> getResult() {
return result;
}
public void setResult(List<ResultBean> result) {
this.result = result;
}
public static class ResultBean {
/**
* pic_s210 : http://business.cdn.qianqian.com/qianqian/pic/bos_client_734232335ef76f5a05179797875817f3.jpg
* bg_pic : http://business0.qianqian.com/qianqian/file/5bfe4e9aa7496_218.png
* color : 0xDC5900
* pic_s444 : http://hiphotos.qianqian.com/ting/pic/item/c83d70cf3bc79f3d98ca8e36b8a1cd11728b2988.jpg
* count : 4
* type : 2
* content : [{"all_rate":"96,128,224,320,flac","song_id":"611238837","rank_change":"0","biaoshi":"lossless,vip,perm-3","author":"陈柯宇","album_id":"611238835","pic_small":"http://qukufile2.qianqian.com/data2/pic/2d5ab3120f08727becfc2803ee5402f7/611740447/611740447.jpg@s_1,w_90,h_90","title":"生僻字","pic_big":"http://qukufile2.qianqian.com/data2/pic/2d5ab3120f08727becfc2803ee5402f7/611740447/611740447.jpg@s_1,w_150,h_150","album_title":"生僻字"},{"all_rate":"96,128,224,320,flac","song_id":"606149060","rank_change":"0","biaoshi":"lossless,perm-1","author":"展展与罗罗","album_id":"606149057","pic_small":"http://qukufile2.qianqian.com/data2/pic/c9aa6f85bf036735c355a05dd373ff0b/606149058/606149058.png@s_1,w_90,h_90","title":"沙漠骆驼","pic_big":"http://qukufile2.qianqian.com/data2/pic/c9aa6f85bf036735c355a05dd373ff0b/606149058/606149058.png@s_1,w_150,h_150","album_title":"沙漠骆驼"},{"all_rate":"96,128,224,320,flac","song_id":"604568155","rank_change":"0","biaoshi":"lossless,vip,perm-1","author":"马良,孙茜茹","album_id":"604568152","pic_small":"http://qukufile2.qianqian.com/data2/pic/f53a667bbf3c11df1da0841fd34c4d9d/604568153/604568153.jpg@s_1,w_90,h_90","title":"往后余生","pic_big":"http://qukufile2.qianqian.com/data2/pic/f53a667bbf3c11df1da0841fd34c4d9d/604568153/604568153.jpg@s_1,w_150,h_150","album_title":"往后余生"},{"all_rate":"96,128,224,320,flac","song_id":"598740690","rank_change":"0","biaoshi":"lossless,perm-3","author":"张杰,张碧晨","album_id":"598740686","pic_small":"http://qukufile2.qianqian.com/data2/pic/2854c6d30aab478cec599a174c911eea/598740687/598740687.jpg@s_1,w_90,h_90","title":"只要平凡","pic_big":"http://qukufile2.qianqian.com/data2/pic/2854c6d30aab478cec599a174c911eea/598740687/598740687.jpg@s_1,w_150,h_150","album_title":"只要平凡"}]
* bg_color : 0xFBEFE6
* web_url :
* name : 热歌榜
* comment : 该榜单是根据千千音乐平台歌曲每周播放量自动生成的数据榜单,统计范围为千千音乐平台上的全部歌曲,每日更新一次
* pic_s192 : http://business.cdn.qianqian.com/qianqian/pic/bos_client_1452f36a8dc430ccdb8f6e57be6df2ee.jpg
* pic_s260 : http://hiphotos.qianqian.com/ting/pic/item/838ba61ea8d3fd1f1326c83c324e251f95ca5f8c.jpg
*/
private String pic_s210;
private String bg_pic;
private String color;
private String pic_s444;
private int count;
private int type;
private String bg_color;
private String web_url;
private String name;
private String comment;
private String pic_s192;
private String pic_s260;
private List<ContentBean> content;
public String getPic_s210() {
return pic_s210;
}
public void setPic_s210(String pic_s210) {
this.pic_s210 = pic_s210;
}
public String getBg_pic() {
return bg_pic;
}
public void setBg_pic(String bg_pic) {
this.bg_pic = bg_pic;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String getPic_s444() {
return pic_s444;
}
public void setPic_s444(String pic_s444) {
this.pic_s444 = pic_s444;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public String getBg_color() {
return bg_color;
}
public void setBg_color(String bg_color) {
this.bg_color = bg_color;
}
public String getWeb_url() {
return web_url;
}
public void setWeb_url(String web_url) {
this.web_url = web_url;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public String getPic_s192() {
return pic_s192;
}
public void setPic_s192(String pic_s192) {
this.pic_s192 = pic_s192;
}
public String getPic_s260() {
return pic_s260;
}
public void setPic_s260(String pic_s260) {
this.pic_s260 = pic_s260;
}
public List<ContentBean> getContent() {
return content;
}
public void setContent(List<ContentBean> content) {
this.content = content;
}
public static class ContentBean {
/**
* all_rate : 96,128,224,320,flac
* song_id : 611238837
* rank_change : 0
* biaoshi : lossless,vip,perm-3
* author : 陈柯宇
* album_id : 611238835
* pic_small : http://qukufile2.qianqian.com/data2/pic/2d5ab3120f08727becfc2803ee5402f7/611740447/611740447.jpg@s_1,w_90,h_90
* title : 生僻字
* pic_big : http://qukufile2.qianqian.com/data2/pic/2d5ab3120f08727becfc2803ee5402f7/611740447/611740447.jpg@s_1,w_150,h_150
* album_title : 生僻字
*/
private String all_rate;
private String song_id;
private String rank_change;
private String biaoshi;
private String author;
private String album_id;
private String pic_small;
private String title;
private String pic_big;
private String album_title;
public String getAll_rate() {
return all_rate;
}
public void setAll_rate(String all_rate) {
this.all_rate = all_rate;
}
public String getSong_id() {
return song_id;
}
public void setSong_id(String song_id) {
this.song_id = song_id;
}
public String getRank_change() {
return rank_change;
}
public void setRank_change(String rank_change) {
this.rank_change = rank_change;
}
public String getBiaoshi() {
return biaoshi;
}
public void setBiaoshi(String biaoshi) {
this.biaoshi = biaoshi;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getAlbum_id() {
return album_id;
}
public void setAlbum_id(String album_id) {
this.album_id = album_id;
}
public String getPic_small() {
return pic_small;
}
public void setPic_small(String pic_small) {
this.pic_small = pic_small;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getPic_big() {
return pic_big;
}
public void setPic_big(String pic_big) {
this.pic_big = pic_big;
}
public String getAlbum_title() {
return album_title;
}
public void setAlbum_title(String album_title) {
this.album_title = album_title;
}
}
}
}
Frag1
package com.bawei.week1.frag;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.Toast;
import com.bawei.week1.R;
import com.bawei.week1.adapter.ListAdapter;
import com.bawei.week1.aysnctask.MyAsyncTask;
import com.bawei.week1.bean.JsonBean;
import com.bawei.week1.http.Http;
import com.google.gson.Gson;
import java.util.List;
/**
* @Auther: 孙鹏飞
* @Date: 2019/2/16 09:39:17
* @Description:
*/
public class Frag1 extends Fragment implements MyAsyncTask.Call{
private ListView listview;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.frag1, container, false);
listview = view.findViewById(R.id.listview);
boolean work = Http.isConnectionWork(getActivity());
if(work){
Toast.makeText(getActivity(),"已联网",Toast.LENGTH_LONG).show();
//MyAsyncTack对象
MyAsyncTask myAsyncTask = new MyAsyncTask();
// 注册接口
myAsyncTask.setCa(this);
//请求数据
myAsyncTask.execute("https://api.apiopen.top/musicRankings");
}else{
Toast.makeText(getActivity(),"无法连接联网",Toast.LENGTH_LONG).show();
}
return view;
}
@Override
public String getData(String s) {
Gson gson = new Gson();
JsonBean jsonBean = gson.fromJson(s, JsonBean.class);
List<JsonBean.ResultBean> result = jsonBean.getResult();
ListAdapter listAdapter = new ListAdapter(result,getActivity());
listview.setAdapter(listAdapter);
return null;
}
}
listAdapter
package com.bawei.week1.adapter;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.bawei.week1.R;
import com.bawei.week1.bean.JsonBean;
import com.bumptech.glide.Glide;
import java.util.ArrayList;
import java.util.List;
/**
* @Auther: 孙鹏飞
* @Date: 2019/2/16 10:54:51
* @Description:
*/
public class ListAdapter extends BaseAdapter{
private List<JsonBean.ResultBean> list;
private Context context;
public ListAdapter(List<JsonBean.ResultBean> list, Context context) {
this.list = list;
this.context = context;
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Haoder hd= new Haoder();
if(convertView==null){
convertView= View.inflate(context,R.layout.item,null);
hd.img=convertView.findViewById(R.id.img);
hd.tx=convertView.findViewById(R.id.text1);
convertView.setTag(hd);
}else{
hd= (Haoder) convertView.getTag();
}
JsonBean.ResultBean resultBean = list.get(position);
hd.tx.setText(resultBean.getName());
Glide.with(context).load(resultBean.getBg_pic()).into(hd.img);
return convertView;
}
class Haoder{
ImageView img;
TextView tx;
}
}
item
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/img"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text1"/>
</LinearLayout>
Frag2
package com.bawei.week1.frag;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.bawei.week1.R;
import com.bawei.week1.http.Http;
/**
* @Auther: 孙鹏飞
* @Date: 2019/2/16 09:40:18
* @Description:
*/
public class Frag2 extends Fragment {
private String picUrl ="http://f.expoon.com//sub//news//2016//01//21//158040_230x162_0.jpg";
private ImageView img;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.frag2, container, false);
img = view.findViewById(R.id.image1);
return view;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
new picAs(img).equals(picUrl);
}
public class picAs extends AsyncTask<String,Void,Bitmap>{
ImageView iv;
public picAs(ImageView iv) {
this.iv=iv;
}
@Override
protected Bitmap doInBackground(String... strings) {
Bitmap pic = Http.pic(strings[0]);
return pic;
}
@Override
protected void onPostExecute(Bitmap bitmap) {
super.onPostExecute(bitmap);
iv.setImageBitmap(bitmap);
}
}
}
mainfests
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bawei.week1">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
com.android.tools.idea.gradle.structure.editors.ModuleDependenciesTableItem@3ae52119 Implementation
com.android.tools.idea.gradle.structure.editors.ModuleDependenciesTableItem@555b2b27 Implementation