編輯:關於Android編程
Android 循環ListView 之前做個iOS下的,實現起來比較復雜,後來在網上找了一個例子,其實現起來比較容易,思路很好,這個我做個整理
代碼下載:http://pan.baidu.com/s/1bnEKxd1
這個類就是個ListView的Adapter沒什麼特別的。
ListAdapter.java
package com.pactera.infinitescrollview; import java.util.List; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; public class ListAdapter extends BaseAdapter{ private Listlist; private LayoutInflater mInflater; public ListAdapter (Context context,List list) { this.list = list; this.mInflater = LayoutInflater.from(context); } @Override public int getCount() { // TODO Auto-generated method stub if (list != null) { //這個內容要是顯示內容的3倍 return list.size() * 3; } return 0; } @Override public Object getItem(int arg0) { // TODO Auto-generated method stub return list.get(arg0 % list.size()); } @Override public long getItemId(int arg0) { // TODO Auto-generated method stub return arg0 % list.size(); } @Override public View getView(int postition, View converView, ViewGroup arg2) { // TODO Auto-generated method stub ViewHoler viewHoler = null; if (converView == null) { viewHoler = new ViewHoler(); converView = mInflater.inflate(R.layout.adapter_list_layout, null); viewHoler.tvText = (TextView)converView.findViewById(R.id.adapter_list_layout_tv); converView.setTag(viewHoler); }else { viewHoler = (ViewHoler)converView.getTag(); } viewHoler.tvText.setText(list.get(postition % list.size())); return converView; } static class ViewHoler{ TextView tvText; } }
MainActivity.java
package com.pactera.infinitescrollview; import java.util.ArrayList; import java.util.List; import android.os.Bundle; import android.app.Activity; import android.util.Log; import android.view.Menu; import android.widget.AbsListView; import android.widget.ListView; import android.widget.AbsListView.OnScrollListener; public class MainActivity extends Activity implements OnScrollListener { private ListView listView; private Listlist; private ListAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listView = (ListView) findViewById(R.id.listView1); list = getList(); adapter = new ListAdapter(this, list); listView.setAdapter(adapter); listView.setOnScrollListener(this); listView.setSelection(list.size()); } public List getList() { List list = new ArrayList (); for (int i = 0; i < 10; i++) { list.add(String.valueOf(i)); } return list; } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { // TODO Auto-generated method stub Log.d("ff", ""+ firstVisibleItem); if (firstVisibleItem <= 2) { listView.setSelection(list.size() + 2); }else if (firstVisibleItem + visibleItemCount > adapter.getCount() - 2) { listView.setSelection(firstVisibleItem - list.size()); } } @Override public void onScrollStateChanged(AbsListView arg0, int arg1) { // TODO Auto-generated method stub } }
重點在上面的onScroll方法 的if語句
留守公司就剩下幾個人了。我沒有年假故還在堅守。廢話不多說,閒來無事。想練習一下自定義控件的應用以及學習圖片類操作以及處理等等。所以我在網上找了大神文章,鴻洋大神的博客。找
一、簡介相信大家用eclipse上的模擬器會覺得很慢很卡,這裡給大家介紹個好東西安卓模擬器genymotion。了解更多,可到此網站https://www.genymot
Android的硬件抽象層,簡單來說,就是對Linux內核驅
項目中最近用到各種圖表,本來打算用第三方的,例如MPAndroid,這是一個十分強大的圖表庫,應用起來十分方便,但是最終發現和設計不太一樣,沒辦法,只能自己寫了。今天將寫
compile 'com.android.suppo