編輯:關於android開發
AndroidManifest.xml
package com.cctvjiatao.pulltorefreshlistviewdemo; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; /** * @作者: jiatao * @修改時間:2016-4-12 下午6:03:08 * @文件名:MainActivity.java * @版權聲明:www.cctvjiatao.com * @功能: 開源插件 PullToRefresh, PullToRefreshListView / PullToRefreshGridView 實例詳解 */ public class MainActivity extends Activity { private Context context; private Button btn1, btn2, btn3, btn4; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); context = this; setContentView(R.layout.act_main); initView(); } private void initView() { btn1 = (Button) findViewById(R.id.btn1); btn2 = (Button) findViewById(R.id.btn2); btn3 = (Button) findViewById(R.id.btn3); btn4 = (Button) findViewById(R.id.btn4); btn1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(context, OnlyPullDownAct.class)); } }); btn2.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(context, BothPullDownUpAct.class)); } }); btn3.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(context, PullGridpAct.class)); } }); btn4.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(context, PullWithCustomTextAct.class)); } }); } }
OnlyPullDownAct.java
package com.cctvjiatao.pulltorefreshlistviewdemo; import java.util.LinkedList; import android.app.Activity; import android.os.AsyncTask; import android.os.Bundle; import android.text.format.DateUtils; import android.util.Log; import android.widget.ArrayAdapter; import android.widget.ListView; import com.handmark.pulltorefresh.library.PullToRefreshBase; import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener; import com.handmark.pulltorefresh.library.PullToRefreshListView; /** * @作者: jiatao * @修改時間:2016-4-12 下午11:39:50 * @包名:com.cctvjiatao.pulltorefreshlistviewdemo * @文件名:OnlyPullDownAct.java * @版權聲明:www.cctvjiatao.com * @功能: 只能下拉的 PullToRefreshListView */ public class OnlyPullDownAct extends Activity { private final String TAG = getClass().getSimpleName(); private LinkedListmListItems; private PullToRefreshListView mPullRefreshListView; private ArrayAdapter mAdapter; private int mItemCount = 9; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.act_pulllist); initDatas(); initView(); setListener(); } /** * 初始化數據 */ private void initDatas() { mListItems = new LinkedList (); for (int i = 0; i < mItemCount; i++) { mListItems.add("" + i); } } /** * 初始化界面 */ private void initView() { // 得到控件 mPullRefreshListView = (PullToRefreshListView) findViewById(R.id.pull_refresh_list); // 設置適配器 mAdapter = new ArrayAdapter (this, android.R.layout.simple_list_item_1, mListItems); mPullRefreshListView.setAdapter(mAdapter); } /** * 設置監聽事件 * 下拉刷新的回調:setOnRefreshListener(new OnRefreshListener (){} */ private void setListener() { mPullRefreshListView.setOnRefreshListener(new OnRefreshListener () { @Override public void onRefresh(PullToRefreshBase refreshView) { Log.e(TAG, "onRefresh"); String label = DateUtils.formatDateTime(getApplicationContext(), System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL); refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);// 顯示最後更新的時間 new GetDataTask().execute();// 模擬加載任務 } }); } /** * 模擬加載任務 * 在回調中模擬了一個異步任務,加載了一個Item */ private class GetDataTask extends AsyncTask { @Override protected String doInBackground(Void... params) { try { Thread.sleep(1000); } catch (InterruptedException e) { } return "" + (mItemCount++); } @Override protected void onPostExecute(String result) { mListItems.add(result); mAdapter.notifyDataSetChanged(); mPullRefreshListView.onRefreshComplete(); } } }
package com.cctvjiatao.pulltorefreshlistviewdemo; import java.util.LinkedList; import android.app.Activity; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; import android.widget.ArrayAdapter; import android.widget.ListView; import com.handmark.pulltorefresh.library.PullToRefreshBase; import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode; import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener2; import com.handmark.pulltorefresh.library.PullToRefreshListView; /** * @作者: jiatao * @修改時間:2016-4-12 下午11:39:50 * @包名:com.cctvjiatao.pulltorefreshlistviewdemo * @文件名:BothPullDownUpAct.java * @版權聲明:www.cctvjiatao.com * @功能: 能上、下拉的 PullToRefreshListView */ public class BothPullDownUpAct extends Activity { private final String TAG = getClass().getSimpleName(); private LinkedListmListItems; private PullToRefreshListView mPullRefreshListView; private ArrayAdapter mAdapter; private int mItemCount = 9; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.act_pulllist); initDatas(); initView(); setListener(); } /** * 初始化數據 */ private void initDatas() { mListItems = new LinkedList (); for (int i = 0; i < mItemCount; i++) { mListItems.add("" + i); } } /** * 初始化界面 */ private void initView() { // 得到控件 mPullRefreshListView = (PullToRefreshListView) findViewById(R.id.pull_refresh_list); mPullRefreshListView.setMode(Mode.BOTH); // 設置適配器 mAdapter = new ArrayAdapter (this, android.R.layout.simple_list_item_1, mListItems); mPullRefreshListView.setAdapter(mAdapter); } /** * 設置監聽事件 * 下拉、上拉刷新的回調setOnRefreshListener(new OnRefreshListener2 (){}); * interface OnRefreshListener2 這個接口包含兩個方法,一個上拉回調,一個下拉回調 * 注:如果上拉和下拉需求是執行一樣的代碼,那麼可以使用回調setOnRefreshListener(new OnRefreshListener (){},上拉和下拉都會執行同一個方法,前提是要設置mPullRefreshListView.setMode(Mode.BOTH)或xml屬性ptr:ptrMode="both" 。 */ private void setListener() { mPullRefreshListView.setOnRefreshListener(new OnRefreshListener2 () { @Override public void onPullDownToRefresh(PullToRefreshBase refreshView) { Log.e(TAG, "onPullDownToRefresh"); // 這裡寫下拉刷新的任務 new GetDataTask().execute(); } @Override public void onPullUpToRefresh(PullToRefreshBase refreshView) { Log.e(TAG, "onPullUpToRefresh"); // 這裡寫上拉加載更多的任務 new GetDataTask().execute(); } }); } /** * 模擬加載任務 在回調中模擬了一個異步任務,加載了一個Item */ private class GetDataTask extends AsyncTask { @Override protected String doInBackground(Void... params) { try { Thread.sleep(1000); } catch (InterruptedException e) { } return "" + (mItemCount++); } @Override protected void onPostExecute(String result) { mListItems.add(result); mAdapter.notifyDataSetChanged(); mPullRefreshListView.onRefreshComplete(); } } }
package com.cctvjiatao.pulltorefreshlistviewdemo; import java.util.LinkedList; import com.handmark.pulltorefresh.library.PullToRefreshBase; import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener2; import com.handmark.pulltorefresh.library.PullToRefreshGridView; import android.app.Activity; import android.os.AsyncTask; import android.os.Bundle; import android.text.format.DateUtils; import android.util.Log; import android.widget.ArrayAdapter; import android.widget.GridView; /** * @作者: jiatao * @修改時間:2016-4-12 下午11:39:50 * @包名:com.cctvjiatao.pulltorefreshlistviewdemo * @文件名:PullGridpAct.java * @版權聲明:www.cctvjiatao.com * @功能: 能上、下拉的 PullToRefreshGridView */ public class PullGridpAct extends Activity { private final String TAG = getClass().getSimpleName(); private LinkedListmListItems; private PullToRefreshGridView mPullRefreshListView; private ArrayAdapter mAdapter; private int mItemCount = 9; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.act_pullgrid); initDatas(); initView(); setListener(); } /** * 初始化數據 */ private void initDatas() { mListItems = new LinkedList (); for (int i = 0; i < mItemCount; i++) { mListItems.add("" + i); } } /** * 初始化界面 */ private void initView() { // 得到控件 mPullRefreshListView = (PullToRefreshGridView) findViewById(R.id.pull_refresh_grid); // 設置適配器 mAdapter = new ArrayAdapter (this, R.layout.item_grid, R.id.id_grid_item_text, mListItems); mPullRefreshListView.setAdapter(mAdapter); } /** * 設置監聽事件 下拉、上拉刷新的回調setOnRefreshListener(new OnRefreshListener2 (){}); * interface OnRefreshListener2 這個接口包含兩個方法,一個上拉回調,一個下拉回調 * 注:如果上拉和下拉需求是執行一樣的代碼,那麼可以使用回調setOnRefreshListener(new OnRefreshListener (){},上拉和下拉都會執行同一個方法, * 前提是要設置mPullRefreshListView.setMode(Mode.BOTH)或xml屬性ptr:ptrMode="both" 。 */ private void setListener() { mPullRefreshListView.setOnRefreshListener(new OnRefreshListener2 () { @Override public void onPullDownToRefresh(PullToRefreshBase refreshView) { Log.e(TAG, "onPullDownToRefresh"); String label = DateUtils.formatDateTime(getApplicationContext(), System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL); refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label); new GetDataTask().execute(); } @Override public void onPullUpToRefresh(PullToRefreshBase refreshView) { Log.e(TAG, "onPullUpToRefresh"); new GetDataTask().execute(); } }); } /** * 模擬加載任務 在回調中模擬了一個異步任務,加載了一個Item */ private class GetDataTask extends AsyncTask { @Override protected String doInBackground(Void... params) { try { Thread.sleep(1000); } catch (InterruptedException e) { } return "" + (mItemCount++); } @Override protected void onPostExecute(String result) { mListItems.add(result); mAdapter.notifyDataSetChanged(); mPullRefreshListView.onRefreshComplete(); } } }
PullWithCustomTextAct.java
package com.cctvjiatao.pulltorefreshlistviewdemo; import java.util.LinkedList; import android.app.Activity; import android.os.AsyncTask; import android.os.Bundle; import android.text.format.DateUtils; import android.util.Log; import android.widget.ArrayAdapter; import android.widget.ListView; import com.handmark.pulltorefresh.library.ILoadingLayout; import com.handmark.pulltorefresh.library.PullToRefreshBase; import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode; import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener2; import com.handmark.pulltorefresh.library.PullToRefreshListView; /** * @作者: jiatao * @修改時間:2016-4-12 下午11:39:50 * @包名:com.cctvjiatao.pulltorefreshlistviewdemo * @文件名:PullWithCustomTextAct.java * @版權聲明:www.cctvjiatao.com * @功能: 設定指示器文本內容 */ public class PullWithCustomTextAct extends Activity { private final String TAG = getClass().getSimpleName(); private LinkedListmListItems; private PullToRefreshListView mPullRefreshListView; private ArrayAdapter mAdapter; private int mItemCount = 9; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.act_pulllist); initDatas(); initView(); setListener(); } /** * 初始化數據 */ private void initDatas() { mListItems = new LinkedList (); for (int i = 0; i < mItemCount; i++) { mListItems.add("" + i); } } /** * 初始化界面 */ private void initView() { // 得到控件 mPullRefreshListView = (PullToRefreshListView) findViewById(R.id.pull_refresh_list); mPullRefreshListView.setMode(Mode.BOTH); //設定指示器文本內容:上拉和下拉的指示器同時改變 initIndicator(); //設定指示器文本內容:上拉和下拉的指示器內容單獨改變 // initIndicator2(); // 設置適配器 mAdapter = new ArrayAdapter (this, android.R.layout.simple_list_item_1, mListItems); mPullRefreshListView.setAdapter(mAdapter); } /** * 設定指示器文本內容 * 默認是上拉和下拉的指示器內容同時改變 */ private void initIndicator() { ILoadingLayout iLoadingLayout = mPullRefreshListView.getLoadingLayoutProxy(); iLoadingLayout.setPullLabel("你可勁拉,拉...");// 剛下拉時,顯示的提示 iLoadingLayout.setRefreshingLabel("好嘞,正在刷新...");// 刷新時 iLoadingLayout.setReleaseLabel("你敢放,我就敢刷新...");// 下來達到一定距離時,顯示的提示 String label = DateUtils.formatDateTime(getApplicationContext(), System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL); iLoadingLayout.setLastUpdatedLabel(label);// 顯示最後更新的時間 } /** * 設定指示器文本內容 * 上拉和下拉的指示器內容單獨改變 * mPullRefreshListView.getLoadingLayoutProxy(true, false) 下拉的指示器 * mPullRefreshListView.getLoadingLayoutProxy(false, true) 上拉的指示器 */ private void initIndicator2() { ILoadingLayout startLabels = mPullRefreshListView.getLoadingLayoutProxy(true, false); startLabels.setPullLabel("你可勁拉,拉...");// 剛下拉時,顯示的提示 startLabels.setRefreshingLabel("好嘞,正在刷新...");// 刷新時 startLabels.setReleaseLabel("你敢放,我就敢刷新...");// 下來達到一定距離時,顯示的提示 ILoadingLayout endLabels = mPullRefreshListView.getLoadingLayoutProxy(false, true); endLabels.setPullLabel("你可勁拉,拉2...");// 剛下拉時,顯示的提示 endLabels.setRefreshingLabel("好嘞,正在刷新2...");// 刷新時 endLabels.setReleaseLabel("你敢放,我就敢刷新2...");// 下來達到一定距離時,顯示的提示 } /** * 設置監聽事件 * 下拉、上拉刷新的回調setOnRefreshListener(new OnRefreshListener2 (){}); * interface OnRefreshListener2 這個接口包含兩個方法,一個上拉回調,一個下拉回調 * 注:如果上拉和下拉需求是執行一樣的代碼,那麼可以使用回調setOnRefreshListener(new OnRefreshListener (){},上拉和下拉都會執行同一個方法,前提是要設置mPullRefreshListView.setMode(Mode.BOTH)或xml屬性ptr:ptrMode="both" 。 */ private void setListener() { mPullRefreshListView.setOnRefreshListener(new OnRefreshListener2 () { @Override public void onPullDownToRefresh(PullToRefreshBase refreshView) { Log.e(TAG, "onPullDownToRefresh"); // 這裡寫下拉刷新的任務 new GetDataTask().execute(); } @Override public void onPullUpToRefresh(PullToRefreshBase refreshView) { Log.e(TAG, "onPullUpToRefresh"); // 這裡寫上拉加載更多的任務 new GetDataTask().execute(); } }); } /** * 模擬加載任務 在回調中模擬了一個異步任務,加載了一個Item */ private class GetDataTask extends AsyncTask { @Override protected String doInBackground(Void... params) { try { Thread.sleep(1000); } catch (InterruptedException e) { } return "" + (mItemCount++); } @Override protected void onPostExecute(String result) { mListItems.add(result); mAdapter.notifyDataSetChanged(); mPullRefreshListView.onRefreshComplete(); } } }
Android中的 Multiple dex files define 編譯錯誤引發的思考 昨天我龍哥問我一個問題,他說如果一個工程中,有一個com.x.A枚舉,導入
利用bintray-release插件上傳到Bintray- HTTP/1.1 404 Not Found [message:Repo 'maven' w
Android工程打包成jar文件,並且將工程中引用的jar一起打入新的jar文件中,androidjar前言: 關於.jar文件: 平時我們Android項目開發中經常
Android與HTML+JS交互入門 在Android開發中,越來越多的商業項目使用了Android原生控件與WebView進行混合開發,當然不僅僅就是顯示一個We