編輯:關於Android編程
上個月,google發布了自己的下拉刷新控件------SwipeRefreshLayout,該控件封裝在android-support-v4.jar包中,依靠監聽OnRefreshListener實現刷新操作。該控件用法十分簡單,setEnable()方法控制刷新是否可用,setRefreshing()方法控制刷新進度條動畫是否可用,由於是要實現下拉刷新,官方文檔明確指出該控件所含有的一個直接子View必須是能夠滾動的,如ListView、ScrollView等等。
要使用該控件,需要現在布局文件定義SwipeRefreshLayout控件,布局文件如下:
package com.example.android_test_swiperefreshlayout; import java.util.ArrayList; import android.os.Bundle; import android.os.Handler; import android.R.integer; import android.app.Activity; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends Activity implements OnRefreshListener { private SwipeRefreshLayout swipeLayout; private ListView listView; private ArrayListlist; private MyAdapter adapter; private int count = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initData(); swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe); swipeLayout.setColorScheme(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light); listView = (ListView) findViewById(R.id.list); adapter = new MyAdapter(); listView.setAdapter(adapter); swipeLayout.setOnRefreshListener(this); } public void initData() { list = new ArrayList (); for (int i = 0; i < 24; i++) { list.add("北京" + i); } count = 24; } class MyAdapter extends BaseAdapter { @Override public int getCount() { // TODO Auto-generated method stub return list.size(); } @Override public Object getItem(int position) { // TODO Auto-generated method stub return list.get(position); } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub if (convertView == null) { convertView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.item, null); } TextView textView = (TextView) convertView.findViewById(R.id.textView1); textView.setText(list.get(position)); return convertView; } } @Override public void onRefresh() { // TODO Auto-generated method stub new Handler().postDelayed(new Runnable() { @Override public void run() { // TODO Auto-generated method stub swipeLayout.setRefreshing(true); list.add("新增北京"+count); count++; adapter.notifyDataSetChanged(); } }, 3000); } }
Android屏幕截圖功能實現這裡介紹兩種方式: 第一種 截取整個屏幕實現方式三種 ImageView imgV = (ImageView) findVie
.xml代碼如下: 顯示如下:
以下資源來sharesdk官方demo中的Sample 1,同登錄一樣配置ShareSDK.xml和AndroidManifest.xml【各平台申請好的key】【上
本文實例講述了Android Service中使用Toast無法正常顯示問題的解決方法。分享給大家供大家參考,具體如下:在做Service簡單練習時,在Service中的