android - Android改造演示列表视图不显示所有回购
问题描述
我正在关注改造教程https://futurestud.io/tutorials/retrofit-getting-started-and-android-client
该应用程序编译并运行,但不允许您滚动超出第一页。知道我错过了什么吗?本教程是否让你展示了所有的 repos?
https://github.com/morenoh149/HarryLearnsAndroid/tree/master/HttpDemo
package com.harrymoreno.httpdemo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.Toast;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import com.harrymoreno.httpdemo.GitHubRepoAdapter;
public class MainActivity extends AppCompatActivity {
private ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.pagination_list);
Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl("https://api.github.com/")
.addConverterFactory(GsonConverterFactory.create());
Retrofit retrofit = builder.build();
GithubClient client = retrofit.create(GithubClient.class);
Call<List<GithubRepo>> call = client.reposForUser("morenoh149");
call.enqueue(new Callback<List<GithubRepo>>() {
@Override
public void onResponse(Call<List<GithubRepo>> call, Response<List<GithubRepo>> response) {
List<GithubRepo> repos = response.body();
listView.setAdapter(new GitHubRepoAdapter(MainActivity.this, repos));
}
@Override
public void onFailure(Call<List<GithubRepo>> call, Throwable t) {
Toast.makeText(MainActivity.this, "error :(", Toast.LENGTH_SHORT).show();
}
});
}
}
和activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ListView
android:id="@+id/pagination_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="0dp" />
</RelativeLayout>
解决方案
在xml文件中使用scrollview然后listview
推荐阅读
- javascript - 如何在前端显示“methods.name.call()”web3 - 方法的结果
- dictionary - 如何在TCL中声明词典词典?
- java - 与循环斗争
- javascript - 所有路线的passportJS身份验证
- sql - 如何在日期中定义过滤器?
- vba - 使用 UNC 路径将选定的 Outlook 电子邮件保存到共享驱动器作为 .msg 文件
- laravel - Laravel - 如何在动态输入表单上应用 Laravel old() 辅助函数
- javascript - 没有 DICTID 和 ADLER32 校验和 nodejs 的 zlib 膨胀
- c++ - 从子类构造函数中构造基类的问题
- kubernetes - 如何设置秘密的默认模式?