{
"kind": "youtube#videoListResponse",
"etag": "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/Lec3r2rhex4s56mAG78uC7O4NOg\"",
"nextPageToken": "CAUQAA",
"pageInfo": {
"totalResults": 200,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#video",
"etag": "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/sshmBPZwvHb0obBLwnC_SxxAMBQ\"",
"id": "Ooke4YZv8Ts",
"snippet": {
"publishedAt": "2019-03-16T20:05:00.000Z",
"channelId": "UCX6OQ3DkcsbYNE6H8uQQuVA",
"title": "Surviving 24 Hours Straight In A Desert",
"description": "WE WENT TO A DESERT AND SPENT 24 HOURS IN IT\n\nNew Merch
这是MainActivity
public class MainActivity extends AppCompatActivity {
String url = "https://www.googleapis.com/youtube/v3/videos?part=snippet%2CcontentDetails%2Cstatistics&chart=mostPopular®ionCode=US&key=AIzaSyDqfH47DVbZT5qXpVn31F5p385cDU38F4o";
ArrayList<Bean>list;
ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
listView = findViewById(R.id.listView);
getData(url);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void getData(String url){
AsyncHttpClient client = new AsyncHttpClient();
client.get(url, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
String response = new String(responseBody);
list = new ArrayList<>();
try {
JSONObject jsonObject = new JSONObject(response);
JSONArray jsonArray = jsonObject.getJSONArray("items");
JSONObject jsonObject1 = null;
for (int i = 0;i <jsonArray.length();i++){
jsonObject1 = jsonArray.getJSONObject(i);
String title = jsonObject1.getJSONObject("snippet").optString("title");
Log.d("TAG","title"+title);
String thumbnail = jsonObject1.getJSONObject("snippet").getJSONObject("thumbnails").getJSONObject("standard").optString("url");
Log.d("TAG","thumbnails :"+thumbnail);
String videoId = jsonObject1.optString("id");
Log.d("TAG"," videoId :"+videoId);
String description = jsonObject1.getJSONObject("snippet").optString("description");
Log.d("TAG","description :"+ description);
String likes = jsonObject1.getJSONObject("statistics").optString("likeCount");
Log.d("TAG","likes :"+likes);
list.add(new Bean(title,thumbnail,videoId,description,likes));
}
Adapter adapter = new Adapter(MainActivity.this,list);
listView.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
}
});
我每页获取5个视频,我想加载我做的下一个视频,如果有任何人可以在此寻找解决方案,可以在互联网上找到任何解决方案,并且我希望加载200个结果在我的应用程序中,我提到了MainActivity并替换了JSON Thats .......