- 浏览: 2490506 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Android Tutorial(2)Endless Pagination for ListView
We have 2 options to load more information in ListView.
1. Add a button or link to the footer of the view, when we press it the system will load more content.
2. Check if the last item is visible and load more content when it is.
First of all, I plan to Viewing Android Source Code in Eclipse. That will help me a lot to study the codes.
1. Get the Android Source Code Viewing
After API Level 14, we have this 'Sources for Android SDK'. But for the previous versions, we need to install a plugin named "Android Sources".
https://code.google.com/p/adt-addons/
I install the plugin with URL
http://adt-addons.googlecode.com/svn/trunk/installer/com.android.ide.eclipse.installer.update/
But got Error Message:
Cannot complete the install because one or more required items could not be found.
Software being installed: Android SDK Installer 0.9.5.201012121703 (com.android.ide.eclipse.installer.feature.feature.group 0.9.5.201012121703)
Missing requirement: Android SDK Installer 0.9.5.201012121703 (com.android.ide.eclipse.installer.feature.feature.group 0.9.5.201012121703) requires 'org.eclipse.gef.all.feature.group 0.0.0' but it could not be found
Solution:
Change to root user and use the latest link:
http://adt-addons.googlecode.com/svn/trunk/source/com.android.ide.eclipse.source.update/
After that I got the source codes of android.
But I need to just use the latest package, do not use root user. That will cause problem if I build from maven. NO root User.
2. Make the Pagination ListView
Some times I got this Error Message when I start my emulator from snapshot.
Starting emulator for AVD 'CARL'
emulator: ERROR: Unable to load VM from snapshot. The snapshot has been saved for a different hardware configuration.
Solution:
Android Virtual Device Manager -> delete AVD -> new AVD, that solved the problem.
Change the adapter not extends from BaseAdapter, but from ArrayAdapter.
package com.sillycat.easyrestclientandroid.adapter;
import java.util.List;
import android.content.Context;
import android.widget.ArrayAdapter;
public abstract class AbstractBaseItemListAdapter<T> extends ArrayAdapter<T> {
public AbstractBaseItemListAdapter(Context context, int textViewResourceId,
List<T> objects) {
super(context, textViewResourceId, objects);
}
}
Almost no changes in the Adapter implementation.
public class ProductsListAdapter extends AbstractBaseItemListAdapter<Product> {
privatefinal LayoutInflater _layoutInflater;
public ProductsListAdapter(Context context, int textViewResourceId,List<Product> objects) {
super(context, textViewResourceId, objects);
this._layoutInflater = LayoutInflater.from(context);
}
…snip…
Most of the changes will happen in the activity.
package com.sillycat.easyrestclientandroid.activity.impl;
import java.util.ArrayList;
import java.util.List;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import com.sillycat.easyrestclientandroid.activity.AbstractAsyncListActivity;
import com.sillycat.easyrestclientandroid.adapter.impl.ProductsListAdapter;
import com.sillycat.easyrestclientandroid.dao.ProductDAO;
import com.sillycat.easyrestclientandroid.dao.mock.ProductMockDAOImpl;
import com.sillycat.easyrestclientandroid.model.Product;
public class ProductsListActivity extends AbstractAsyncListActivity {
protected static final String TAG = ProductsListActivity.class
.getSimpleName();
int pageSize = 5;
int currentPage = 1;
boolean loadingMore = false;
ProductsListAdapter adapter;
List<Product> items;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
items = new ArrayList<Product>();
adapter = new ProductsListAdapter(this,
android.R.layout.simple_list_item_1, items);
setListAdapter(adapter);
}
public void onStart() {
super.onStart();
new DownloadStatesTask().execute(currentPage);
}
public void refreshStates(List<Product> items) {
if (items == null || items.isEmpty()) {
return;
}
for (int i = 0; i < items.size(); i++) {
adapter.add(items.get(i));
}
setTitle("Products List with " + String.valueOf(adapter.getCount())
+ " items");
adapter.notifyDataSetChanged();
this.getListView().setOnScrollListener(new OnScrollListener() {
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
int lastInScreen = firstVisibleItem + visibleItemCount;
Log.d(TAG, "firstVisibleItem = " + firstVisibleItem + " visibleItemCount = " + visibleItemCount + " totalItemCount = " + totalItemCount);
if ((lastInScreen == totalItemCount) && !(loadingMore)) {
currentPage = currentPage + 1;
new DownloadStatesTask().execute(currentPage);
}
}
});
loadingMore = false;
}
private class DownloadStatesTask extends
AsyncTask<Integer, Void, List<Product>> {
@Override
protected void onPreExecute() {
loadingMore = true;
showLoadingProgressDialog();
}
@Override
protected List<Product> doInBackground(Integer... params) {
try {
Log.d(TAG, "Hitting the current page params = " + params[0]);
ProductDAO dao = new ProductMockDAOImpl();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
}
return dao.pagination(params[0], pageSize);
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
}
return null;
}
@Override
protected void onPostExecute(List<Product> result) {
dismissProgressDialog();
refreshStates(result);
}
}
}
References:
http://p-xr.com/android-tutorial-dynamicaly-load-more-items-to-the-listview-never-ending-list/
Source Plugin
http://manski.net/2011/11/android-source-code-in-eclipse/
http://adt-addons.googlecode.com/svn/trunk/source/com.android.ide.eclipse.source.update/
Customer ArrayAdatper
http://www.ezzylearning.com/tutorial.aspx?tid=1763429
http://devtut.wordpress.com/2011/06/09/custom-arrayadapter-for-a-listview-android/
http://sogacity.com/how-to-make-a-custom-arrayadapter-for-listview/
We have 2 options to load more information in ListView.
1. Add a button or link to the footer of the view, when we press it the system will load more content.
2. Check if the last item is visible and load more content when it is.
First of all, I plan to Viewing Android Source Code in Eclipse. That will help me a lot to study the codes.
1. Get the Android Source Code Viewing
After API Level 14, we have this 'Sources for Android SDK'. But for the previous versions, we need to install a plugin named "Android Sources".
https://code.google.com/p/adt-addons/
I install the plugin with URL
http://adt-addons.googlecode.com/svn/trunk/installer/com.android.ide.eclipse.installer.update/
But got Error Message:
Cannot complete the install because one or more required items could not be found.
Software being installed: Android SDK Installer 0.9.5.201012121703 (com.android.ide.eclipse.installer.feature.feature.group 0.9.5.201012121703)
Missing requirement: Android SDK Installer 0.9.5.201012121703 (com.android.ide.eclipse.installer.feature.feature.group 0.9.5.201012121703) requires 'org.eclipse.gef.all.feature.group 0.0.0' but it could not be found
Solution:
Change to root user and use the latest link:
http://adt-addons.googlecode.com/svn/trunk/source/com.android.ide.eclipse.source.update/
After that I got the source codes of android.
But I need to just use the latest package, do not use root user. That will cause problem if I build from maven. NO root User.
2. Make the Pagination ListView
Some times I got this Error Message when I start my emulator from snapshot.
Starting emulator for AVD 'CARL'
emulator: ERROR: Unable to load VM from snapshot. The snapshot has been saved for a different hardware configuration.
Solution:
Android Virtual Device Manager -> delete AVD -> new AVD, that solved the problem.
Change the adapter not extends from BaseAdapter, but from ArrayAdapter.
package com.sillycat.easyrestclientandroid.adapter;
import java.util.List;
import android.content.Context;
import android.widget.ArrayAdapter;
public abstract class AbstractBaseItemListAdapter<T> extends ArrayAdapter<T> {
public AbstractBaseItemListAdapter(Context context, int textViewResourceId,
List<T> objects) {
super(context, textViewResourceId, objects);
}
}
Almost no changes in the Adapter implementation.
public class ProductsListAdapter extends AbstractBaseItemListAdapter<Product> {
privatefinal LayoutInflater _layoutInflater;
public ProductsListAdapter(Context context, int textViewResourceId,List<Product> objects) {
super(context, textViewResourceId, objects);
this._layoutInflater = LayoutInflater.from(context);
}
…snip…
Most of the changes will happen in the activity.
package com.sillycat.easyrestclientandroid.activity.impl;
import java.util.ArrayList;
import java.util.List;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import com.sillycat.easyrestclientandroid.activity.AbstractAsyncListActivity;
import com.sillycat.easyrestclientandroid.adapter.impl.ProductsListAdapter;
import com.sillycat.easyrestclientandroid.dao.ProductDAO;
import com.sillycat.easyrestclientandroid.dao.mock.ProductMockDAOImpl;
import com.sillycat.easyrestclientandroid.model.Product;
public class ProductsListActivity extends AbstractAsyncListActivity {
protected static final String TAG = ProductsListActivity.class
.getSimpleName();
int pageSize = 5;
int currentPage = 1;
boolean loadingMore = false;
ProductsListAdapter adapter;
List<Product> items;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
items = new ArrayList<Product>();
adapter = new ProductsListAdapter(this,
android.R.layout.simple_list_item_1, items);
setListAdapter(adapter);
}
public void onStart() {
super.onStart();
new DownloadStatesTask().execute(currentPage);
}
public void refreshStates(List<Product> items) {
if (items == null || items.isEmpty()) {
return;
}
for (int i = 0; i < items.size(); i++) {
adapter.add(items.get(i));
}
setTitle("Products List with " + String.valueOf(adapter.getCount())
+ " items");
adapter.notifyDataSetChanged();
this.getListView().setOnScrollListener(new OnScrollListener() {
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
int lastInScreen = firstVisibleItem + visibleItemCount;
Log.d(TAG, "firstVisibleItem = " + firstVisibleItem + " visibleItemCount = " + visibleItemCount + " totalItemCount = " + totalItemCount);
if ((lastInScreen == totalItemCount) && !(loadingMore)) {
currentPage = currentPage + 1;
new DownloadStatesTask().execute(currentPage);
}
}
});
loadingMore = false;
}
private class DownloadStatesTask extends
AsyncTask<Integer, Void, List<Product>> {
@Override
protected void onPreExecute() {
loadingMore = true;
showLoadingProgressDialog();
}
@Override
protected List<Product> doInBackground(Integer... params) {
try {
Log.d(TAG, "Hitting the current page params = " + params[0]);
ProductDAO dao = new ProductMockDAOImpl();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
}
return dao.pagination(params[0], pageSize);
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
}
return null;
}
@Override
protected void onPostExecute(List<Product> result) {
dismissProgressDialog();
refreshStates(result);
}
}
}
References:
http://p-xr.com/android-tutorial-dynamicaly-load-more-items-to-the-listview-never-ending-list/
Source Plugin
http://manski.net/2011/11/android-source-code-in-eclipse/
http://adt-addons.googlecode.com/svn/trunk/source/com.android.ide.eclipse.source.update/
Customer ArrayAdatper
http://www.ezzylearning.com/tutorial.aspx?tid=1763429
http://devtut.wordpress.com/2011/06/09/custom-arrayadapter-for-a-listview-android/
http://sogacity.com/how-to-make-a-custom-arrayadapter-for-listview/
发表评论
-
ionic UI(4)ionic2 framework - basic and components and native
2016-03-24 02:33 1228ionic UI(4)ionic2 framework - b ... -
ionic UI(3)TypeScript - handbook
2016-03-22 23:21 593ionic UI(3)TypeScript - handboo ... -
ionic UI(2)ionic2 framework - TypeScript - tutorial
2016-03-22 06:52 1621ionic UI(2)ionic2 framework - T ... -
Parse and Heroku Service(3)Parse Server and Parse Dashboard
2016-03-22 06:30 943Parse and Heroku Service(3)Pars ... -
Parse and Heroku Service(2)Mail Templates and Push Notification
2016-03-22 02:45 543Parse and Heroku Service(2)Mail ... -
ionic UI(1)Introduction
2016-03-19 03:18 682ionic UI(1)Introduction 1 Inst ... -
Parse and Heroku Service(1)Heroku Installation and Play
2016-03-19 00:13 787Parse and Heroic Service(1)Hero ... -
Hybrid(5)Customize Meteor Directly Google Login
2015-09-01 02:33 888Hybrid(5)Customize Meteor Direc ... -
Hybrid(4)Favorite Places - Google Login
2015-09-01 02:02 1299Hybrid(4)Favorite Places - Goog ... -
Hybrid(3)More Meteor Example - Social
2015-08-11 05:04 729Hybrid(3)More Meteor Example - ... -
Hybrid(2)meteor Running Android and iOS
2015-07-28 23:59 1007Hybrid(2)meteor Running Android ... -
Create the Google Play Account
2015-07-18 06:42 1058Create the Google Play Account ... -
Secure REST API and Mobile(1)Document Read and Understand OAUTH2
2015-07-14 00:36 732Secure REST API and Mobile(1)Do ... -
Screen Size and Web Design
2015-07-11 01:11 694Screen Size and Web Design iPh ... -
Hybrid(1)ionic Cordova meteor
2015-06-25 05:49 431Hybrid(1)ionic Cordova meteor ... -
Android Fire Project(1)Recall Env and Knowledge
2015-02-11 12:28 651Android Fire Project(1)Recall ... -
Android Content Framework(1)Concept
2014-06-14 13:54 1050Android Content Framework(1)Con ... -
Feel Android Studio(1)Install and Update Android Studio
2014-04-11 03:12 1977Feel Android Studio(1)Install a ... -
IOS7 App Development Essentials(2)iBeacon
2014-03-05 05:55 852IOS7 App Development Essentials ... -
IOS7 App Development Essentials(1) Persistent Store
2014-03-05 05:54 1278IOS7 App Development Essentials ...
相关推荐
OpenGL ES Tutorial for Android – Part I – Setting up the view OpenGL ES Tutorial for Android – Part II – Building a polygon OpenGL ES Tutorial for Android – Part III – Transformations OpenGL ES ...
android advanced tutorial
Tutorial on OpenCV for Android Setup
Android Development Tutorial Nikhil Yadav CSE40816/60816 - Pervasive Health Fall 2011
Android Tutorial1 Android Tutorial2 官网中文教程 Design framework 2016.04.15 navigate draw Task1 2016.04.17 Task2 2016.04.19 Task3 2016.04.20 Figure out hybrid ARQ strategy Task4 2016.04.21...
roman10-android-tutorial包含了android tutorial的所有源码
android ndk tutorial guide for android development
这是我自己学习android的作品. 共享一下, 需要的朋友可拿去参考一下. Android中的tutorials比较详细,但是没有提供实例. 如果操作中有什么地方搞错了,比较难查问题,特别是初学者. 我提供这个下载也是方便大家在学习时...
FLUENT 2020R2 tutorial guide PDF及案例源文件 1.What’s In This Manual The ANSYS Fluent Tutorial Guide contains a number of tutorials that teach you how to use ANSYS Flu- ent to solve different types ...
Tutorial on SVMs for Pattern Recognition SVM的入门文档
本分步工作簿重点介绍ArcGIS Pro,但同时也 涵盖了ArcGIS OnlineSM及其一些主要的移动计算应用程序,包括Esri®Story Map, 适用于ArcGIS®的Operations Dashboard和适用于ArcGIS®的Collector
Docker Docker Tutorial for Beginners Build Ship and Run 英文azw3 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
Android is an open-source, Linux-based operating system for mobile devices such as smartphones and tablet computers. Android was developed by the Open Handset Alliance, led by Google, and other ...
Tutorial_Artificial Intelligence for Drug Discovery
tutorial_cut down for running.R
Code project corresponding to a serials of tutorial posts for android unit testing 本文是一系列发表在我的个人博客,关于安卓单元测试的文章的实例代码。 代码与文章的对应关系如下: Android单元测试: 首先,...
63.[开源][安卓]roman10-android-tutorial-master roman10-android-tutorial包含了android tutorial的所有源代码。
Java2 Tutorial-5.0
Webdynpro for ABAP tutorial