【发布时间】:2017-09-29 11:09:02
【问题描述】:
我正在为一个在线博客开发一个从其 API 检索数据的 Android 应用程序(该公司制作了它,以便我可以在其中使用它,因此可以对其进行修改)。
该应用会显示一个 ListView,其中加载了 n 个博客条目。问题是我过去三天一直在寻找一种在所述 ListView 底部添加上一个/下一个按钮的方法,只是为了最终放弃并尝试另一种方法。
我看到当用户在列表上上下滚动时,应用会更新并将从服务器拉取的内容附加到列表(不确定是哪种类型)。
这可能吗?如果可以,怎么做?
任何有启发性的信息、示例(尽可能简单)或帮助将不胜感激!
额外信息
我在一个 LinearLineout 中加载 ListView,它在 onCreate 方法中被调用。
content_main.xml
<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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.company.myApp.MainActivity"
tools:showIn="@layout/app_bar_main"
tools:layout_editor_absoluteY="81dp"
tools:layout_editor_absoluteX="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="@color/myGrey"
android:scrollbars="none"
android:visibility="visible" />
</LinearLayout>
</LinearLayout>
我还使用自定义适配器用检索到的数据填充 ListView。此数据由自定义类检索并存储在 List 中,然后将该列表作为参数传递给我用来设置此类适配器的方法。
public class AdaptadorPosts extends ArrayAdapter {
public AdaptadorPosts(Context context, List objects) {
super(context, 0, objects);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = convertView;
if (null == convertView) {
v = inflater.inflate(R.layout.lista_posts, parent, false);
}
TextView titulo = (TextView)v.findViewById(R.id.titulo);
TextView resumen = (TextView)v.findViewById(R.id.resumen);
TextView fecha = (TextView)v.findViewById(R.id.fecha);
TextView autor = (TextView)v.findViewById(R.id.autor);
Post item = (Post) getItem(position);
titulo.setText(Html.fromHtml(item.getTitulo()));
if(item.getResumen().isEmpty() || item.getResumen().equals(null)) {
resumen.setText("¡No hay resumen!");
} else {
resumen.setText(Html.fromHtml(item.getResumen()));
}
fecha.setText(Html.fromHtml(item.getFecha()));
autor.setText(Html.fromHtml(item.getAutor().getNombre()));
return v;
}
}
【问题讨论】:
-
这个东西叫做延迟加载这里是例子blogs.innovationm.com/…
标签: java android api listview adapter