QQ第三方登陆,上拉加载下拉刷新XListView结合微信精选第三方分享加ImageLoad

 

QQ第三方登陆,上拉加载下拉刷新XListView结合微信精选第三方分享加ImageLoad


//QQ第三方登陆,上拉加载下拉刷新XListView结合微信精选第三方分享加ImageLoad

*******************抱歉的是有乱码,还请见谅,开始建项目的时候要把GBK改成UTF-8就可以了*************


    ***********************配置XLIstView的string.xml文件***************************

[java]  view plain  copy
  1. <string name="xlistview_header_hint_normal">下拉刷新</string>  
  2.   <string name="xlistview_header_hint_ready">松开刷新数据</string>  
  3.   <string name="xlistview_header_hint_loading">正在加载...</string>  
  4.   <string name="xlistview_header_last_time">上次更新时间:</string>  
  5.   <string name="xlistview_footer_hint_normal">查看更多</string>  
  6.   <string name="xlistview_footer_hint_ready">松开载入更多</string>  


*****************************配置第三方QQ登陆和分享********************************************


[java]  view plain  copy
  1. <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />  
  2.     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />  
  3.     <uses-permission android:name="android.permission.READ_PHONE_STATE" />  
  4.     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />  
  5.     <uses-permission android:name="android.permission.INTERNET" />  
  6.     <uses-permission android:name="android.permission.READ_LOGS" />  
  7.     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />  
  8.     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />  
  9.     <uses-permission android:name="android.permission.GET_TASKS" />  
  10.     <uses-permission android:name="android.permission.SET_DEBUG_APP" />  
  11.     <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />  
  12.     <uses-permission android:name="android.permission.GET_ACCOUNTS" />  
  13.     <uses-permission android:name="android.permission.USE_CREDENTIALS" />  
  14.     <uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />  
  15.     <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />  
  16.     <uses-permission android:name="android.permission.RECORD_AUDIO" />  
  17.     <uses-permission android:name="android.permission.VIBRATE" />  
  18.     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />  
  19.     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />  
  20.     <uses-permission android:name="android.permission.READ_PHONE_STATE" />  
  21.     <uses-permission android:name="android.permission.INTERNET" />  
  22.     <uses-permission android:name="android.permission.CALL_PHONE" />  
  23.     <uses-permission android:name="android.permission.WAKE_LOCK" />  
  24.     <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />  
  25.     <uses-permission android:name="android.permission.CAMERA" />  
  26.     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />  
  27.     <uses-permission android:name="android.permission.WRITE_SETTINGS" />  


[java]  view plain  copy
  1. <activity  
  2.            android:name="com.tencent.tauth.AuthActivity"  
  3.            android:launchMode="singleTask"  
  4.            android:noHistory="true" >  
  5.            <intent-filter>  
  6.                <action android:name="android.intent.action.VIEW" />  
  7.   
  8.                <category android:name="android.intent.category.DEFAULT" />  
  9.                <category android:name="android.intent.category.BROWSABLE" />  
  10.   
  11.                <data android:scheme="tencent100424468" />  
  12.            </intent-filter>  
  13.        </activity>  
  14.        <activity  
  15.            android:name="com.tencent.connect.common.AssistActivity"  
  16.            android:screenOrientation="portrait"  
  17.            android:theme="@android:style/Theme.Translucent.NoTitleBar" />  
  18.        <activity  
  19.            android:name="com.umeng.socialize.editorpage.ShareActivity"  
  20.            android:excludeFromRecents="true"  
  21.            android:theme="@style/Theme.UMDefault" />  
  22.   
  23.        <meta-data  
  24.            android:name="UMENG_APPKEY"  
  25.            android:value="4eaee02c527015373b000003" >  
  26.        </meta-data>  


******************************Main函数中的全部代码**************************************

[java]  view plain  copy
  1. import java.net.HttpURLConnection;  
  2. import java.net.URL;  
  3. import java.util.ArrayList;  
  4. import java.util.Map;  
  5. import java.util.Set;  
  6.   
  7. import android.app.Activity;  
  8. import android.app.ProgressDialog;  
  9. import android.content.Intent;  
  10. import android.graphics.BitmapFactory;  
  11. import android.os.Bundle;  
  12. import android.os.Handler;  
  13. import android.view.View;  
  14. import android.widget.AbsListView;  
  15. import android.widget.AbsListView.OnScrollListener;  
  16. import android.widget.AdapterView;  
  17. import android.widget.AdapterView.OnItemClickListener;  
  18. import android.widget.AdapterView.OnItemLongClickListener;  
  19. import android.widget.ImageView;  
  20. import android.widget.TextView;  
  21. import android.widget.Toast;  
  22.   
  23. import com.example.day17qq_weixin.WeiChatInfo.MyList;  
  24. import com.example.day17qq_weixin.view.XListView;  
  25. import com.example.day17qq_weixin.view.XListView.IXListViewListener;  
  26. import com.google.gson.Gson;  
  27. import com.nostra13.universalimageloader.core.DisplayImageOptions;  
  28. import com.nostra13.universalimageloader.core.ImageLoader;  
  29. import com.umeng.socialize.ShareAction;  
  30. import com.umeng.socialize.UMAuthListener;  
  31. import com.umeng.socialize.UMShareAPI;  
  32. import com.umeng.socialize.UMShareListener;  
  33. import com.umeng.socialize.bean.SHARE_MEDIA;  
  34. import com.umeng.socialize.media.UMImage;  
  35.   
  36. public class MainActivity extends Activity implements IXListViewListener{  
  37.   
  38.     protected static final String TAG = "MainActivity";  
  39.     private UMShareAPI mShareAPI;  
  40.     protected static final int SUCEESS = 0;  
  41.     private XListView listView;  
  42.     private int index = 1;  
  43.     // 锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷  
  44.     private ArrayList<MyList> myList = new ArrayList<WeiChatInfo.MyList>();  
  45.     private MyBase myBase;  
  46.     Handler handler = new Handler() {  
  47.   
  48.         public void handleMessage(android.os.Message msg) {  
  49.             if (msg.what == SUCEESS) {  
  50.                 progressDialog.dismiss();  
  51.                 WeiChatInfo chatInfo = (WeiChatInfo) msg.obj;  
  52.                 if (chatInfo.error_code == 0) {  
  53.                     myList.addAll(chatInfo.result.list);  
  54.                     if (myBase == null) {  
  55.                         myBase = new MyBase(MainActivity.this,  
  56.                                 myList);  
  57.                         listView.setAdapter(myBase);  
  58.                     } else {  
  59.                         myBase.notifyDataSetChanged();  
  60.                     }  
  61.                 }  
  62.             }  
  63.         };  
  64.     };  
  65.     private ProgressDialog progressDialog;  
  66.     private UMImage image;  
  67.   
  68.     @Override  
  69.     protected void onCreate(Bundle savedInstanceState) {  
  70.         super.onCreate(savedInstanceState);  
  71.         setContentView(R.layout.activity_main);  
  72.           
  73.         mShareAPI = UMShareAPI.get(this);  
  74.         platform = SHARE_MEDIA.QQ;  
  75.         imageView = (ImageView) findViewById(R.id.imageView);  
  76.         tv_name = (TextView) findViewById(R.id.tv_name);  
  77.         listView = (XListView) findViewById(R.id.listView);  
  78.         listView.setPullLoadEnable(true);  
  79.         listView.setXListViewListener(this);  
  80.           
  81.           
  82.         initOptions = ImageLoaderUtils.initOptions();  
  83.         image = new UMImage(this,  
  84.                 BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));  
  85.           
  86.         listView.setOnScrollListener(new OnScrollListener() {  
  87.   
  88.             @Override  
  89.             public void onScrollStateChanged(AbsListView view, int scrollState) {  
  90.                 int lastVisiblePosition = view.getLastVisiblePosition();  
  91.                 if (scrollState == OnScrollListener.SCROLL_STATE_IDLE  
  92.                         && lastVisiblePosition == myList.size() - 1) {  
  93.                     index++;  
  94.                     getData();  
  95.                       
  96.                 }  
  97.             }  
  98.   
  99.             @Override  
  100.             public void onScroll(AbsListView view, int firstVisibleItem,  
  101.                     int visibleItemCount, int totalItemCount) {  
  102.   
  103.             }  
  104.         });  
  105.         listView.setOnItemClickListener(new OnItemClickListener() {  
  106.   
  107.             @Override  
  108.             public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,  
  109.                     long arg3) {  
  110.                 // TODO Auto-generated method stub  
  111.                 Intent intent = new Intent(MainActivity.this, ShowActivity.class);  
  112.                 intent.putExtra("url", myList.get(arg2-1).url);  
  113.                 startActivity(intent);  
  114.                   
  115.             }  
  116.         });  
  117.         //长按监听  
  118.         listView.setOnItemLongClickListener(new OnItemLongClickListener() {  
  119.   
  120.             private UMShareListener umShareListener;  
  121.   
  122.             @Override  
  123.             public boolean onItemLongClick(AdapterView<?> arg0, View arg1,  
  124.                     int arg2, long arg3) {  
  125.                 // TODO Auto-generated method stub  
  126.               
  127.                 //分享  
  128.                 final SHARE_MEDIA[] displaylist = new SHARE_MEDIA[]  
  129.                         {  
  130.                             SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE,SHARE_MEDIA.SINA,  
  131.                             SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE,SHARE_MEDIA.DOUBAN  
  132.                         };  
  133.                 new ShareAction(MainActivity.this).setDisplayList( displaylist )  
  134.                         .withText( "锟角猴拷" )  
  135.                         .withTitle("title")  
  136.                         .withTargetUrl(myList.get(arg2).url)  
  137.                         .withMedia( image )  
  138.                         .setListenerList(umShareListener)  
  139.                         .open();  
  140.   
  141. //              new ShareAction(MainActivity.this)  
  142. //              .setPlatform(SHARE_MEDIA.SINA)  
  143. //              .setCallback(umShareListener)  
  144. //              .withText("hello umeng video")  
  145. //              .withTargetUrl("http://www.baidu.com")  
  146. //              .withMedia(image)  
  147. //              .share();  
  148.                 umShareListener=new UMShareListener() {  
  149.                     @Override  
  150.                     public void onResult(SHARE_MEDIA platform) {  
  151.                         Toast.makeText(MainActivity.this,platform + "分享成功啦", Toast.LENGTH_SHORT).show();  
  152.                     }  
  153.   
  154.                     @Override  
  155.                     public void onError(SHARE_MEDIA platform, Throwable t) {  
  156.                         Toast.makeText(MainActivity.this,platform + " 分享失败啦", Toast.LENGTH_SHORT).show();  
  157.                     }  
  158.   
  159.                     @Override  
  160.                     public void onCancel(SHARE_MEDIA platform) {  
  161.                         Toast.makeText(MainActivity.this,platform + " 分享取消了", Toast.LENGTH_SHORT).show();  
  162.                     }  
  163.                 };  
  164.                 return true;  
  165.             }  
  166.         });  
  167.   
  168.         getData();  
  169.     }  
  170.   
  171.     protected void getData() {  
  172.         // TODO Auto-generated method stub  
  173.         progressDialog = new ProgressDialog(this);  
  174.         progressDialog.setTitle("正在努力加载中...");  
  175.         progressDialog.show();  
  176.         new Thread() {  
  177.             public void run() {  
  178.                 try {  
  179.                     // http://v.juhe.cn/weixin/query?key=锟斤拷锟斤拷锟斤拷锟終EY  
  180.                     // 0917c812f187b92e025c9b7c2d4e59b5 pno  
  181.                     String path = "http://v.juhe.cn/weixin/query?key=518bccce2abaeb7f08101e47ed5f5891&pno="  
  182.                             + index;  
  183.                     URL url = new URL(path);  
  184.                     HttpURLConnection openConnection = (HttpURLConnection) url  
  185.                             .openConnection();  
  186.                     openConnection.setConnectTimeout(5000);  
  187.                     openConnection.setReadTimeout(5000);  
  188.                     int responseCode = openConnection.getResponseCode();  
  189.                     if (responseCode == 200) {  
  190.                         InputStream inputStream = openConnection  
  191.                                 .getInputStream();  
  192.                         String parseSteam = StreamUtils.parseSteam(inputStream);  
  193.                         Gson gson = new Gson();  
  194.                         WeiChatInfo weiChatInfo = gson.fromJson(parseSteam,  
  195.                                 WeiChatInfo.class);  
  196.                         // 发送消息  
  197.                         handler.obtainMessage(SUCEESS, weiChatInfo)  
  198.                                 .sendToTarget();  
  199.                     }  
  200.                 } catch (Exception e) {  
  201.                     e.printStackTrace();  
  202.                 }  
  203.             };  
  204.         }.start();  
  205.     }  
  206.   
  207.     public void login(View v) {  
  208.         mShareAPI.doOauthVerify(this, platform, umAuthListener);  
  209.     }  
  210.   
  211.     public void sinaLogin(View v) {  
  212.         mShareAPI = UMShareAPI.get(this);  
  213.         SHARE_MEDIA platform = SHARE_MEDIA.SINA;  
  214.         // 锟饺诧拷去锟斤拷取平台锟斤拷息  
  215.         mShareAPI.doOauthVerify(this, platform, umAuthListener);  
  216.     }  
  217.   
  218.     private boolean flag = true;  
  219.   
  220.     private UMAuthListener umAuthListener = new UMAuthListener() {  
  221.         @Override  
  222.         public void onComplete(SHARE_MEDIA platform, int action,  
  223.                 Map<String, String> data) {  
  224.             Toast.makeText(getApplicationContext(), "Authorize succeed",  
  225.                     Toast.LENGTH_SHORT).show();  
  226.             // 锟叫断碉拷前锟斤拷牵锟斤拷锟斤拷锟斤拷true锟斤拷锟酵斤拷锟叫碉拷锟斤拷..  
  227.             if (flag) {  
  228.                 mShareAPI.getPlatformInfo(MainActivity.this, platform,  
  229.                         umAuthListener);  
  230.                 flag = false;  
  231.             }  
  232.             if (action == 2) {  
  233.                 Set<String> keySet = data.keySet();  
  234.                 for (String key : keySet) {  
  235.                     String value = data.get(key);  
  236.                     System.out.println("key-----" + key  
  237.                             + "value-----" + value);  
  238.                     // Toast.makeText(getActivity(), "key-----" +  
  239.                     // key + "value-----" + value, 0).show();  
  240.                 }  
  241.                 try {  
  242.                     String names = data.get("screen_name")  
  243.                             .toString();  
  244.                     String image = data.get("profile_image_url")  
  245.                             .toString();  
  246.                     if (image.equals(null) || image.equals("")) {  
  247.                         Toast.makeText(MainActivity.this"锟斤拷取图片失锟杰o拷"0)  
  248.                                 .show();  
  249.                         return;  
  250.                     }  
  251.                 ImageLoader.getInstance().displayImage(image, imageView,initOptions);  
  252.                 tv_name.setText(names);  
  253.                 } catch (Exception e) {  
  254.                     // TODO: handle exception  
  255.                 }  
  256.             }  
  257.               
  258.   
  259.         }  
  260.   
  261.         @Override  
  262.         public void onError(SHARE_MEDIA platform, int action, Throwable t) {  
  263.             Toast.makeText(getApplicationContext(), "Authorize fail",  
  264.                     Toast.LENGTH_SHORT).show();  
  265.         }  
  266.   
  267.         @Override  
  268.         public void onCancel(SHARE_MEDIA platform, int action) {  
  269.             Toast.makeText(getApplicationContext(), "Authorize cancel",  
  270.                     Toast.LENGTH_SHORT).show();  
  271.         }  
  272.     };  
  273.     private SHARE_MEDIA platform;  
  274.     private ImageView imageView;  
  275.     private TextView tv_name;  
  276.     private DisplayImageOptions initOptions;  
  277.   
  278.     @Override  
  279.     protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
  280.         super.onActivityResult(requestCode, resultCode, data);  
  281.         if (mShareAPI != null)  
  282.             mShareAPI.onActivityResult(requestCode, resultCode, data);  
  283.          UMShareAPI.get( this ).onActivityResult( requestCode, resultCode, data);  
  284. //          mShareAPI.onActivityResult(requestCode, resultCode, data);  
  285.     }  
  286.   
  287.     @Override  
  288.     public void onRefresh() {  
  289.         // TODO Auto-generated method stub  
  290.         myList.clear();  
  291.         getData();  
  292.         onLoad();  
  293.         myBase.notifyDataSetChanged();  
  294.     }  
  295.   
  296.   
  297.     private void onLoad() {  
  298.         // TODO Auto-generated method stub  
  299.         listView.stopRefresh();  
  300.         listView.stopLoadMore();  
  301.         listView.setRefreshTime("刚刚");  
  302.     }  
  303.   
  304.     @Override  
  305.     public void onLoadMore() {  
  306.         // TODO Auto-generated method stub  
  307.         myList.clear();  
  308.         getData();  
  309.         onLoad();  
  310.         myBase.notifyDataSetChanged();  
  311.     }  
  312. }  

*****************************ImageLoaderUtils工具类*******************************

[java]  view plain  copy
  1. public static void initConfiguration(Context context) {  
  2.      Builder builder = new ImageLoaderConfiguration.Builder(context);  
  3.         ImageLoader.getInstance().init(builder.build());  
  4.     }  
  5.   
  6.     public static DisplayImageOptions initOptions() {  
  7.         DisplayImageOptions displayImageOptions = new DisplayImageOptions.Builder()  
  8.                 .showImageOnLoading(R.drawable.ic_launcher)  
  9.                 .showImageForEmptyUri(R.drawable.ic_launcher)  
  10.                 .cacheInMemory(true).cacheOnDisk(true).build();  
  11.         return displayImageOptions;  
  12.     }  



*************************************MyApplication*************************************


[java]  view plain  copy
  1. public class MyApplication extends Application {  
  2.     @Override  
  3.     public void onCreate() {  
  4.         // TODO Auto-generated method stub  
  5.         super.onCreate();  
  6.         PlatformConfig.setQQZone("100424468""c7394704798a158208a74ab60104f0ba");   
  7.                 ImageLoaderUtils.initConfiguration(getApplicationContext());  
  8.         //http://v.juhe.cn/weixin/query?key=518bccce2abaeb7f08101e47ed5f5891  
  9.   
  10.     }  
  11.   
  12. }  


*****************************************MyBaseAdapter适配器*****************************************


[java]  view plain  copy
  1. public class MyBase extends BaseAdapter {  
  2.   
  3.     private MainActivity context;  
  4.     private ArrayList<MyList> list;  
  5.     private DisplayImageOptions initOptions;  
  6.   
  7.     public MyBase(MainActivity mainActivity, ArrayList<MyList> list) {  
  8.         this.context = mainActivity;  
  9.         this.list = list;  
  10.         initOptions = ImageLoaderUtils.initOptions();  
  11.     }  
  12.     @Override  
  13.     public int getCount() {  
  14.         // TODO Auto-generated method stub  
  15.         return list.size();  
  16.     }  
  17.   
  18.     @Override  
  19.     public Object getItem(int arg0) {  
  20.         // TODO Auto-generated method stub  
  21.         return list.get(arg0);  
  22.     }  
  23.   
  24.     @Override  
  25.     public long getItemId(int arg0) {  
  26.         // TODO Auto-generated method stub  
  27.         return arg0;  
  28.     }  
  29.   
  30.     @Override  
  31.     public View getView(int arg0, View arg1, ViewGroup arg2) {  
  32.         // TODO Auto-generated method stub  
  33.         View view = View.inflate(context, R.layout.list_item, null);  
  34.         ImageView iv_image = (ImageView) view.findViewById(R.id.iv_image);  
  35.         TextView tv_title = (TextView) view.findViewById(R.id.tv_title);  
  36.         tv_title.setText(list.get(arg0).title);  
  37. //      BitmapUtils bitmapUtils = new BitmapUtils(context);  
  38. //      bitmapUtils.display(iv_image, list.get(arg0).firstImg);  
  39.         ImageLoader.getInstance().displayImage(list.get(arg0).firstImg, iv_image, initOptions);  
  40.         return view;  
  41.     }  
  42.   
  43. }  

******************************StreamUitls网络获取工具类**********************************

[java]  view plain  copy
  1. public class StreamUtils {  
  2.     public static String parseSteam(InputStream inputStream) {  
  3.         try {  
  4.             // 
  5.             ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();  
  6.             // 
  7.             byte[] buffer = new byte[1024];  
  8.             //
  9.             int len = 0;  
  10.             while ((len = inputStream.read(buffer)) != -1) {  
  11.                 //
  12.                 arrayOutputStream.write(buffer, 0, len);  
  13.             }  
  14.             // 
  15.             return arrayOutputStream.toString("utf-8");  
  16.             //
  17.         } catch (IOException e) {  
  18.             e.printStackTrace();  
  19.         }  
  20.         return null;  
  21.     }  
  22. }  


**********************************微信精选的Bean类******************************

[java]  view plain  copy
  1. public class WeiChatInfo {  
  2.     public int error_code;  
  3.     public String reason;  
  4.     public WeiChatResult result;  
  5.   
  6.     public class WeiChatResult {  
  7.         public int pno;  
  8.         public int ps;  
  9.         public int totalPage;  
  10.         public ArrayList<MyList> list;  
  11.   
  12.     }  
  13.     public class MyList{  
  14.         public String firstImg;  
  15.         public String id;  
  16.         public String mark;  
  17.         public String title;  
  18.         public String source;  
  19.         public String url;  
  20.     }  
  21. }  

******************************把QQ第三方登陆的所有的包和文件导入dome******************************

******************************把XListView的三个工具类导入项目****************************************

*******************************XListView工具类******************************

[java]  view plain  copy
  1. import android.content.Context;  
  2. import android.util.AttributeSet;  
  3. import android.view.MotionEvent;  
  4. import android.view.View;  
  5. import android.view.ViewTreeObserver.OnGlobalLayoutListener;  
  6. import android.view.animation.DecelerateInterpolator;  
  7. import android.widget.AbsListView;  
  8. import android.widget.AbsListView.OnScrollListener;  
  9. import android.widget.ListAdapter;  
  10. import android.widget.ListView;  
  11. import android.widget.RelativeLayout;  
  12. import android.widget.Scroller;  
  13. import android.widget.TextView;  
  14.   
  15. import com.example.day17qq_weixin.R;  
  16.   
  17. public class XListView extends ListView implements OnScrollListener {  
  18.   
  19.     private float mLastY = -1// save event y  
  20.     private Scroller mScroller; // used for scroll back  
  21.     private OnScrollListener mScrollListener; // user's scroll listener  
  22.   
  23.     // the interface to trigger refresh and load more.  
  24.     private IXListViewListener mListViewListener;  
  25.     // -- header view  
  26.     private XListViewHeader mHeaderView;  
  27.     // header view content, use it to calculate the Header's height. And hide it  
  28.     // when disable pull refresh.  
  29.     private RelativeLayout mHeaderViewContent;  
  30.     private TextView mHeaderTimeView;  
  31.     private int mHeaderViewHeight; // header view's height  
  32.     private boolean mEnablePullRefresh = true;  
  33.     private boolean mPullRefreshing = false// is refreashing.  
  34.   
  35.     // -- footer view  
  36.     private XListViewFooter mFooterView;  
  37.     private boolean mEnablePullLoad;  
  38.     private boolean mPullLoading;  
  39.     private boolean mIsFooterReady = false;  
  40.   
  41.     // total list items, used to detect is at the bottom of listview.  
  42.     private int mTotalItemCount;  
  43.   
  44.     // for mScroller, scroll back from header or footer.  
  45.     private int mScrollBack;  
  46.     private final static int SCROLLBACK_HEADER = 0;  
  47.     private final static int SCROLLBACK_FOOTER = 1;  
  48.   
  49.     private final static int SCROLL_DURATION = 400// scroll back duration  
  50.     private final static int PULL_LOAD_MORE_DELTA = 50// when pull up >= 50px  
  51.                                                         // at bottom, trigger  
  52.                                                         // load more.  
  53.     private final static float OFFSET_RADIO = 1.8f; // support iOS like pull  
  54.                                                     // feature.  
  55.   
  56.     /** 
  57.      * @param context 
  58.      */  
  59.     public XListView(Context context) {  
  60.         super(context);  
  61.         initWithContext(context);  
  62.     }  
  63.   
  64.     public XListView(Context context, AttributeSet attrs) {  
  65.         super(context, attrs);  
  66.         initWithContext(context);  
  67.     }  
  68.   
  69.     public XListView(Context context, AttributeSet attrs, int defStyle) {  
  70.         super(context, attrs, defStyle);  
  71.         initWithContext(context);  
  72.     }  
  73.   
  74.     private void initWithContext(Context context) {  
  75.         mScroller = new Scroller(context, new DecelerateInterpolator());  
  76.         // XListView need the scroll event, and it will dispatch the event to  
  77.         // user's listener (as a proxy).  
  78.         super.setOnScrollListener(this);  
  79.   
  80.         // init header view  
  81.         mHeaderView = new XListViewHeader(context);  
  82.         mHeaderViewContent = (RelativeLayout) mHeaderView  
  83.                 .findViewById(R.id.xlistview_header_content);  
  84.         mHeaderTimeView = (TextView) mHeaderView  
  85.                 .findViewById(R.id.xlistview_header_time);  
  86.         addHeaderView(mHeaderView);  
  87.   
  88.         // init footer view  
  89.         mFooterView = new XListViewFooter(context);  
  90.   
  91.         // init header height  
  92.         mHeaderView.getViewTreeObserver().addOnGlobalLayoutListener(  
  93.                 new OnGlobalLayoutListener() {  
  94.                     @Override  
  95.                     public void onGlobalLayout() {  
  96.                         mHeaderViewHeight = mHeaderViewContent.getHeight();  
  97.                         getViewTreeObserver()  
  98.                                 .removeGlobalOnLayoutListener(this);  
  99.                     }  
  100.                 });  
  101.     }  
  102.   
  103.     @Override  
  104.     public void setAdapter(ListAdapter adapter) {  
  105.         // make sure XListViewFooter is the last footer view, and only add once.  
  106.         if (mIsFooterReady == false) {  
  107.             mIsFooterReady = true;  
  108.             addFooterView(mFooterView);  
  109.         }  
  110.         super.setAdapter(adapter);  
  111.     }  
  112.   
  113.     /** 
  114.      * enable or disable pull down refresh feature. 
  115.      *  
  116.      * @param enable 
  117.      */  
  118.     public void setPullRefreshEnable(boolean enable) {  
  119.         mEnablePullRefresh = enable;  
  120.         if (!mEnablePullRefresh) { // disable, hide the content  
  121.             mHeaderViewContent.setVisibility(View.INVISIBLE);  
  122.         } else {  
  123.             mHeaderViewContent.setVisibility(View.VISIBLE);  
  124.         }  
  125.     }  
  126.   
  127.     /** 
  128.      * enable or disable pull up load more feature. 
  129.      *  
  130.      * @param enable 
  131.      */  
  132.     public void setPullLoadEnable(boolean enable) {  
  133.         mEnablePullLoad = enable;  
  134.         if (!mEnablePullLoad) {  
  135.             mFooterView.hide();  
  136.             mFooterView.setOnClickListener(null);  
  137.             // make sure "pull up" don't show a line in bottom when listview  
  138.             // with one page  
  139.             setFooterDividersEnabled(false);  
  140.         } else {  
  141.             mPullLoading = false;  
  142.             mFooterView.show();  
  143.             mFooterView.setState(XListViewFooter.STATE_NORMAL);  
  144.             // make sure "pull up" don't show a line in bottom when listview  
  145.             // with one page  
  146.             setFooterDividersEnabled(true);  
  147.             // both "pull up" and "click" will invoke load more.  
  148.             mFooterView.setOnClickListener(new OnClickListener() {  
  149.                 @Override  
  150.                 public void onClick(View v) {  
  151.                     startLoadMore();  
  152.                 }  
  153.             });  
  154.         }  
  155.     }  
  156.   
  157.     /** 
  158.      * stop refresh, reset header view. 
  159.      */  
  160.     public void stopRefresh() {  
  161.         if (mPullRefreshing == true) {  
  162.             mPullRefreshing = false;  
  163.             resetHeaderHeight();  
  164.         }  
  165.     }  
  166.   
  167.     /** 
  168.      * stop load more, reset footer view. 
  169.      */  
  170.     public void stopLoadMore() {  
  171.         if (mPullLoading == true) {  
  172.             mPullLoading = false;  
  173.             mFooterView.setState(XListViewFooter.STATE_NORMAL);  
  174.         }  
  175.     }  
  176.   
  177.     /** 
  178.      * set last refresh time 
  179.      *  
  180.      * @param time 
  181.      */  
  182.     public void setRefreshTime(String time) {  
  183.         mHeaderTimeView.setText(time);  
  184.     }  
  185.   
  186.     private void invokeOnScrolling() {  
  187.         if (mScrollListener instanceof OnXScrollListener) {  
  188.             OnXScrollListener l = (OnXScrollListener) mScrollListener;  
  189.             l.onXScrolling(this);  
  190.         }  
  191.     }  
  192.   
  193.     private void updateHeaderHeight(float delta) {  
  194.         mHeaderView.setVisiableHeight((int) delta  
  195.                 + mHeaderView.getVisiableHeight());  
  196.         if (mEnablePullRefresh && !mPullRefreshing) { // 未处于刷新状态,更新箭头  
  197.             if (mHeaderView.getVisiableHeight() > mHeaderViewHeight) {  
  198.                 mHeaderView.setState(XListViewHeader.STATE_READY);  
  199.             } else {  
  200.                 mHeaderView.setState(XListViewHeader.STATE_NORMAL);  
  201.             }  
  202.         }  
  203.         setSelection(0); // scroll to top each time  
  204.     }  
  205.   
  206.     /** 
  207.      * reset header view's height. 
  208.      */  
  209.     private void resetHeaderHeight() {  
  210.         int height = mHeaderView.getVisiableHeight();  
  211.         if (height == 0// not visible.  
  212.             return;  
  213.         // refreshing and header isn't shown fully. do nothing.  
  214.         if (mPullRefreshing && height <= mHeaderViewHeight) {  
  215.             return;  
  216.         }  
  217.         int finalHeight = 0// default: scroll back to dismiss header.  
  218.         // is refreshing, just scroll back to show all the header.  
  219.         if (mPullRefreshing && height > mHeaderViewHeight) {  
  220.             finalHeight = mHeaderViewHeight;  
  221.         }  
  222.         mScrollBack = SCROLLBACK_HEADER;  
  223.         mScroller.startScroll(0, height, 0, finalHeight - height,  
  224.                 SCROLL_DURATION);  
  225.         // trigger computeScroll  
  226.         invalidate();  
  227.     }  
  228.   
  229.     private void updateFooterHeight(float delta) {  
  230.         int height = mFooterView.getBottomMargin() + (int) delta;  
  231.         if (mEnablePullLoad && !mPullLoading) {  
  232.             if (height > PULL_LOAD_MORE_DELTA) { // height enough to invoke load  
  233.                 mFooterView.setState(XListViewFooter.STATE_READY);  
  234.             } else {  
  235.                 mFooterView.setState(XListViewFooter.STATE_NORMAL);  
  236.             }  
  237.         }  
  238.         mFooterView.setBottomMargin(height);  
  239.   
  240.         // setSelection(mTotalItemCount - 1); // scroll to bottom  
  241.     }  
  242.   
  243.     private void resetFooterHeight() {  
  244.         int bottomMargin = mFooterView.getBottomMargin();  
  245.         if (bottomMargin > 0) {  
  246.             mScrollBack = SCROLLBACK_FOOTER;  
  247.             mScroller.startScroll(0, bottomMargin, 0, -bottomMargin,  
  248.                     SCROLL_DURATION);  
  249.             invalidate();  
  250.         }  
  251.     }  
  252.   
  253.     private void startLoadMore() {  
  254.         mPullLoading = true;  
  255.         mFooterView.setState(XListViewFooter.STATE_LOADING);  
  256.         if (mListViewListener != null) {  
  257.             mListViewListener.onLoadMore();  
  258.         }  
  259.     }  
  260.   
  261.     @Override  
  262.     public boolean onTouchEvent(MotionEvent ev) {  
  263.         if (mLastY == -1) {  
  264.             mLastY = ev.getRawY();  
  265.         }  
  266.         switch (ev.getAction()) {  
  267.         case MotionEvent.ACTION_DOWN:  
  268.             mLastY = ev.getRawY();  
  269.             break;  
  270.         case MotionEvent.ACTION_MOVE:  
  271.             final float deltaY = ev.getRawY() - mLastY;  
  272.             mLastY = ev.getRawY();  
  273.             if (getFirstVisiblePosition() == 0  
  274.                     && (mHeaderView.getVisiableHeight() > 0 || deltaY > 0)) {  
  275.                 // the first item is showing, header has shown or pull down.  
  276.                 updateHeaderHeight(deltaY / OFFSET_RADIO);  
  277.                 invokeOnScrolling();  
  278.             } else if (getLastVisiblePosition() == mTotalItemCount - 1  
  279.                     && (mFooterView.getBottomMargin() > 0 || deltaY < 0)) {  
  280.                 // last item, already pulled up or want to pull up.  
  281.                 updateFooterHeight(-deltaY / OFFSET_RADIO);  
  282.             }  
  283.             break;  
  284.         case MotionEvent.ACTION_CANCEL:  
  285.         case MotionEvent.ACTION_UP:  
  286.             mLastY = -1// reset  
  287.             if (getFirstVisiblePosition() == 0) {  
  288.                 // invoke refresh  
  289.                 if (mEnablePullRefresh  
  290.                         && mHeaderView.getVisiableHeight() > mHeaderViewHeight) {  
  291.                     mPullRefreshing = true;  
  292.                     mHeaderView.setState(XListViewHeader.STATE_REFRESHING);  
  293.                     if (mListViewListener != null) {  
  294.                         mListViewListener.onRefresh();  
  295.                     }  
  296.                 }  
  297.                 resetHeaderHeight();  
  298.                   
  299.             } else if (getLastVisiblePosition() == mTotalItemCount - 1) {  
  300.                 // invoke load more.  
  301.                 if (mEnablePullLoad  
  302.                         && mFooterView.getBottomMargin() > PULL_LOAD_MORE_DELTA  
  303.                         && !mPullLoading) {  
  304.                     startLoadMore();  
  305.                 }  
  306.                 resetFooterHeight();  
  307.             }  
  308.             break;  
  309.         }  
  310.         return super.onTouchEvent(ev);  
  311.     }  
  312.   
  313.     @Override  
  314.     public void computeScroll() {  
  315.         if (mScroller.computeScrollOffset()) {  
  316.             if (mScrollBack == SCROLLBACK_HEADER) {  
  317.                 mHeaderView.setVisiableHeight(mScroller.getCurrY());  
  318.             } else {  
  319.                 mFooterView.setBottomMargin(mScroller.getCurrY());  
  320.             }  
  321.             postInvalidate();  
  322.             invokeOnScrolling();  
  323.         }  
  324.         super.computeScroll();  
  325.     }  
  326.   
  327.     @Override  
  328.     public void setOnScrollListener(OnScrollListener l) {  
  329.         mScrollListener = l;  
  330.     }  
  331.   
  332.     @Override  
  333.     public void onScrollStateChanged(AbsListView view, int scrollState) {  
  334.         if (mScrollListener != null) {  
  335.             mScrollListener.onScrollStateChanged(view, scrollState);  
  336.         }  
  337.     }  
  338.   
  339.     @Override  
  340.     public void onScroll(AbsListView view, int firstVisibleItem,  
  341.             int visibleItemCount, int totalItemCount) {  
  342.         // send to user's listener  
  343.         mTotalItemCount = totalItemCount;  
  344.         if (mScrollListener != null) {  
  345.             mScrollListener.onScroll(view, firstVisibleItem, visibleItemCount,  
  346.                     totalItemCount);  
  347.         }  
  348.     }  
  349.   
  350.     public void setXListViewListener(IXListViewListener l) {  
  351.         mListViewListener = l;  
  352.     }  
  353.   
  354.     /** 
  355.      * you can listen ListView.OnScrollListener or this one. it will invoke 
  356.      * onXScrolling when header/footer scroll back. 
  357.      */  
  358.     public interface OnXScrollListener extends OnScrollListener {  
  359.         public void onXScrolling(View view);  
  360.     }  
  361.   
  362.     /** 
  363.      * implements this interface to get refresh/load more event. 
  364.      */  
  365.     public interface IXListViewListener {  
  366.         public void onRefresh();  
  367.   
  368.         public void onLoadMore();  
  369.     }  
  370. }  

*******************************XListViewFooter工具类******************************

[java]  view plain  copy
  1. import android.content.Context;  
  2. import android.util.AttributeSet;  
  3. import android.view.LayoutInflater;  
  4. import android.view.View;  
  5. import android.widget.LinearLayout;  
  6. import android.widget.TextView;  
  7.   
  8. import com.example.day17qq_weixin.R;  
  9.   
  10. public class XListViewFooter extends LinearLayout {  
  11.     public final static int STATE_NORMAL = 0;  
  12.     public final static int STATE_READY = 1;  
  13.     public final static int STATE_LOADING = 2;  
  14.   
  15.     private Context mContext;  
  16.   
  17.     private View mContentView;  
  18.     private View mProgressBar;  
  19.     private TextView mHintView;  
  20.       
  21.     public XListViewFooter(Context context) {  
  22.         super(context);  
  23.         initView(context);  
  24.     }  
  25.       
  26.     public XListViewFooter(Context context, AttributeSet attrs) {  
  27.         super(context, attrs);  
  28.         initView(context);  
  29.     }  
  30.   
  31.       
  32.     public void setState(int state) {  
  33.         mHintView.setVisibility(View.INVISIBLE);  
  34.         mProgressBar.setVisibility(View.INVISIBLE);  
  35.         mHintView.setVisibility(View.INVISIBLE);  
  36.         if (state == STATE_READY) {  
  37.             mHintView.setVisibility(View.VISIBLE);  
  38.             mHintView.setText(R.string.xlistview_footer_hint_ready);  
  39.         } else if (state == STATE_LOADING) {  
  40.             mProgressBar.setVisibility(View.VISIBLE);  
  41.         } else {  
  42.             mHintView.setVisibility(View.VISIBLE);  
  43.             mHintView.setText(R.string.xlistview_footer_hint_normal);  
  44.         }  
  45.     }  
  46.       
  47.     public void setBottomMargin(int height) {  
  48.         if (height < 0return ;  
  49.         LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)mContentView.getLayoutParams();  
  50.         lp.bottomMargin = height;  
  51.         mContentView.setLayoutParams(lp);  
  52.     }  
  53.       
  54.     public int getBottomMargin() {  
  55.         LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)mContentView.getLayoutParams();  
  56.         return lp.bottomMargin;  
  57.     }  
  58.       
  59.       
  60.     /** 
  61.      * normal status 
  62.      */  
  63.     public void normal() {  
  64.         mHintView.setVisibility(View.VISIBLE);  
  65.         mProgressBar.setVisibility(View.GONE);  
  66.     }  
  67.       
  68.       
  69.     /** 
  70.      * loading status  
  71.      */  
  72.     public void loading() {  
  73.         mHintView.setVisibility(View.GONE);  
  74.         mProgressBar.setVisibility(View.VISIBLE);  
  75.     }  
  76.       
  77.     /** 
  78.      * hide footer when disable pull load more 
  79.      */  
  80.     public void hide() {  
  81.         LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)mContentView.getLayoutParams();  
  82.         lp.height = 0;  
  83.         mContentView.setLayoutParams(lp);  
  84.     }  
  85.       
  86.     /** 
  87.      * show footer 
  88.      */  
  89.     public void show() {  
  90.         LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)mContentView.getLayoutParams();  
  91.         lp.height = LayoutParams.WRAP_CONTENT;  
  92.         mContentView.setLayoutParams(lp);  
  93.     }  
  94.       
  95.     private void initView(Context context) {  
  96.         mContext = context;  
  97.         LinearLayout moreView = (LinearLayout)LayoutInflater.from(mContext).inflate(R.layout.xlistview_footer, null);  
  98.         addView(moreView);  
  99.         moreView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));  
  100.           
  101.         mContentView = moreView.findViewById(R.id.xlistview_footer_content);  
  102.         mProgressBar = moreView.findViewById(R.id.xlistview_footer_progressbar);  
  103.         mHintView = (TextView)moreView.findViewById(R.id.xlistview_footer_hint_textview);  
  104.     }  
  105.       
  106.       
  107. }  


*******************************XListViewHeader工具类******************************


[java]  view plain  copy
  1. import android.content.Context;  
  2. import android.util.AttributeSet;  
  3. import android.view.Gravity;  
  4. import android.view.LayoutInflater;  
  5. import android.view.View;  
  6. import android.view.animation.Animation;  
  7. import android.view.animation.RotateAnimation;  
  8. import android.widget.ImageView;  
  9. import android.widget.LinearLayout;  
  10. import android.widget.ProgressBar;  
  11. import android.widget.TextView;  
  12.   
  13. import com.example.day17qq_weixin.R;  
  14.   
  15. public class XListViewHeader extends LinearLayout {  
  16.     private LinearLayout mContainer;  
  17.     private ImageView mArrowImageView;  
  18.     private ProgressBar mProgressBar;  
  19.     private TextView mHintTextView;  
  20.     private int mState = STATE_NORMAL;  
  21.   
  22.     private Animation mRotateUpAnim;  
  23.     private Animation mRotateDownAnim;  
  24.   
  25.     private final int ROTATE_ANIM_DURATION = 180;  
  26.   
  27.     public final static int STATE_NORMAL = 0;  
  28.     public final static int STATE_READY = 1;  
  29.     public final static int STATE_REFRESHING = 2;  
  30.   
  31.     public XListViewHeader(Context context) {  
  32.         super(context);  
  33.         initView(context);  
  34.     }  
  35.   
  36.     /** 
  37.      * @param context 
  38.      * @param attrs 
  39.      */  
  40.     public XListViewHeader(Context context, AttributeSet attrs) {  
  41.         super(context, attrs);  
  42.         initView(context);  
  43.     }  
  44.   
  45.     private void initView(Context context) {  
  46.         // 初始情况,设置下拉刷新view高度为0  
  47.         LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(  
  48.                 LayoutParams.FILL_PARENT, 0);  
  49.         // 将下拉刷新的view添加进来  
  50.         mContainer = (LinearLayout) LayoutInflater.from(context).inflate(  
  51.                 R.layout.xlistview_header, null);  
  52.         addView(mContainer, lp);  
  53.         setGravity(Gravity.BOTTOM);  
  54.   
  55.         mArrowImageView = (ImageView) findViewById(R.id.xlistview_header_arrow);  
  56.         mHintTextView = (TextView) findViewById(R.id.xlistview_header_hint_textview);  
  57.         mProgressBar = (ProgressBar) findViewById(R.id.xlistview_header_progressbar);  
  58.         // 准备向上和向下的动画  
  59.         mRotateUpAnim = new RotateAnimation(0.0f, -180.0f,  
  60.                 Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,  
  61.                 0.5f);  
  62.         // 设置旋转时间间隔  
  63.         mRotateUpAnim.setDuration(ROTATE_ANIM_DURATION);  
  64.         mRotateUpAnim.setFillAfter(true);  
  65.         mRotateDownAnim = new RotateAnimation(-180.0f, 0.0f,  
  66.                 Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,  
  67.                 0.5f);  
  68.         mRotateDownAnim.setDuration(ROTATE_ANIM_DURATION);  
  69.         mRotateDownAnim.setFillAfter(true);  
  70.     }  
  71.   
  72.     public void setState(int state) {  
  73.         if (state == mState)  
  74.             return;  
  75.         // 如果当前状态是正在刷新  
  76.         if (state == STATE_REFRESHING) { // 显示进度  
  77.             // 移除动画  
  78.             mArrowImageView.clearAnimation();  
  79.             // 设置imageView不可见  
  80.             mArrowImageView.setVisibility(View.INVISIBLE);  
  81.             // 设置progressBar可见  
  82.             mProgressBar.setVisibility(View.VISIBLE);  
  83.         } else { // 显示箭头图片  
  84.             // 只要不是正在刷新,进度条可见,imageView不可见  
  85.             mArrowImageView.setVisibility(View.VISIBLE);  
  86.             mProgressBar.setVisibility(View.INVISIBLE);  
  87.         }  
  88.   
  89.         switch (state) {  
  90.         case STATE_NORMAL:  
  91.             if (mState == STATE_READY) {  
  92.                 mArrowImageView.startAnimation(mRotateDownAnim);  
  93.             }  
  94.             if (mState == STATE_REFRESHING) {  
  95.                 mArrowImageView.clearAnimation();  
  96.             }  
  97.             mHintTextView.setText(R.string.xlistview_header_hint_normal);  
  98.             break;  
  99.         case STATE_READY:  
  100.             if (mState != STATE_READY) {  
  101.                 mArrowImageView.clearAnimation();  
  102.                 mArrowImageView.startAnimation(mRotateUpAnim);  
  103.                 mHintTextView.setText(R.string.xlistview_header_hint_ready);  
  104.             }  
  105.             break;  
  106.         case STATE_REFRESHING:  
  107.             mHintTextView.setText(R.string.xlistview_header_hint_loading);  
  108.             break;  
  109.         default:  
  110.         }  
  111.         mState = state;  
  112.     }  
  113.   
  114.     public void setVisiableHeight(int height) {  
  115.         if (height < 0)  
  116.             height = 0;  
  117.         LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mContainer  
  118.                 .getLayoutParams();  
  119.         lp.height = height;  
  120.         mContainer.setLayoutParams(lp);  
  121.     }  
  122.   
  123.     public int getVisiableHeight() {  
  124.         return mContainer.getLayoutParams().height;  
  125.     }  
  126.   
  127. }  

***************************************activity_main.xml布局************************************

[java]  view plain  copy
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent" >  
  5.   
  6.     <ImageView  
  7.         android:id="@+id/imageView"  
  8.         android:layout_width="100dp"  
  9.         android:layout_height="100dp"  
  10.         android:layout_alignParentLeft="true"  
  11.         android:layout_alignParentTop="true"  
  12.         android:src="@drawable/ic_launcher" />  
  13.   
  14.     <TextView  
  15.         android:id="@+id/tv_name"  
  16.         android:layout_width="wrap_content"  
  17.         android:layout_height="wrap_content"  
  18.         android:layout_alignParentTop="true"  
  19.         android:layout_marginTop="40dp"  
  20.         android:layout_toRightOf="@+id/imageView"  
  21.         android:text="用户名"  
  22.         android:textColor="#ff00ff" />  
  23.   
  24.     <Button  
  25.         android:id="@+id/login"  
  26.         android:layout_width="wrap_content"  
  27.         android:layout_height="wrap_content"  
  28.         android:layout_alignBottom="@+id/imageView"  
  29.         android:layout_alignParentRight="true"  
  30.         android:onClick="login"  
  31.         android:text="QQ登陆"  
  32.         android:textColor="#ff00ff" />  
  33.   
  34.     <com.example.day17qq_weixin.view.XListView  
  35.         android:id="@+id/listView"  
  36.         android:layout_width="match_parent"  
  37.         android:layout_height="wrap_content"  
  38.         android:layout_alignParentLeft="true"  
  39.         android:layout_below="@+id/imageView"  
  40.         android:layout_marginTop="17dp" >  
  41.     </com.example.day17qq_weixin.view.XListView>  
  42.   
  43. </RelativeLayout>  


*********************************ShowActivity详情页*************************************

[java]  view plain  copy
  1. public class ShowActivity extends Activity {  
  2.   
  3.     private WebView webView;  
  4.   
  5.     @Override  
  6.     protected void onCreate(Bundle savedInstanceState) {  
  7.         super.onCreate(savedInstanceState);  
  8.         setContentView(R.layout.activity_show);  
  9.           
  10.         webView = (WebView) findViewById(R.id.webView);  
  11.         //
  12.         Intent intent = getIntent();  
  13.         String string = intent.getStringExtra("url");  
  14.         webView.getSettings().setJavaScriptEnabled(true);  
  15.         webView.setWebViewClient(new WebViewClient());  
  16.         Toast.makeText(ShowActivity.this"..."0).show();  
  17.         webView.loadUrl(string);  
  18.     }  
  19. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值