2. Drop-down refresh, two-dimensional code

Source: Internet
Author: User
Tags try catch

Drop-down Refresh
  • Pulltorefresh

    • Support Listview,webview,gridview,expandablelistview Many controls

      1,lv_list = refreshListView.getRefreshableView();//需要拿到refreshListView这个组合控件里面的具体的listview,才可以设置adapter2.refreshListView.setRefreshing();//开始加载数据的时候.应该显示.正在刷新3.refreshListView.onRefreshComplete();//结束刷新状态4.  refreshListView.setOnRefreshListener(new OnRefreshListener() {@Overridepublic void onRefresh() {    //下拉刷新中.我们应该去重写请求数据    initData();    System.out.println("===setOnRefreshListener====");}});
  • Xlistview: Easy to modify layout

    • Only ListView supported
    • Key methods

      xlv.setPullLoadEnable(true);//开启上拉加载更多xlv.setPullRefreshEnable(true);//开启下拉刷新xlv.stopRefresh();//停止刷新xlv.stopLoadMore();//停止加载更多xlv.setXListViewListener(new IXListViewListener() {//设置监听@Overridepublic void onRefresh() {    handler.sendMessageDelayed(new Message(), 2000);}@Overridepublic void onLoadMore() {    for (int i = 0; i < 100; i++) {        String str = "这个是一个item条目 " + i;        dataSource.add(str);    }    handler.sendMessageDelayed(new Message(), 2000);}});xlv.setRefreshTime(preUpdateTime2);//设置上次更新时间
Encapsulation of the network engine
    • The network request is encapsulated into the cloudengine.class and exposed in the form of a method;
    • Processing of all network request results. Callback back by means of interface method;
Interface callbacks
    • Handler mechanism +thread
    • How to understand the interface callback--the interface callback is a notification mechanism
    • Effect: 1. Simple notification 2. Notification + value
    • Steps:
      • 1. Define interfaces, and interface methods
      • 2. Defining Interface Objects
      • 3. In a certain place. Interface Object Call interface method
      • 4. Exposing interface Objects (construction method, setter method)
Asynctask Basic Use
onPredoInbackGrouponpost
Asynctask Source Code Analysis
private static final int CORE_POOL_SIZE = 5;        //核心线程数private static final int MAXIMUM_POOL_SIZE = 128;   //最大线程数private static final int KEEP_ALIVE = 1;            
Asynctask defects
    • 1. At the same time there are only 5 threads to access the network--this is the point
    • 2. The number of threads is more than 128, will throw an exception--this situation is actually OK;
Asynctask Version Differences
    • COREPOOLsize maximum_poolsize KEEPalive on different versions. The value is not the same;
    • 1.5 was executed serially. One task at a time
    • Previous versions of 1.6-2.3. is executed in parallel. Perform 5 tasks at a time
    • Serial and parallel are provided after 3.0, and the default is serial

      executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, null);//串行executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null);//并行
Asynctask Simple Package

Actual development we will inherit asynctask.

Asynctask functional encapsulation, Asynctask function invocation interface Callback instance
    //1.    public static interface OnCheckedChangeListener {    void onCheckedChanged(CompoundButton buttonView, boolean isChecked);   }    //2.    private OnCheckedChangeListener mOnCheckedChangeListener;    //3.    mOnCheckedChangeListener.onCheckedChanged(this, mChecked);    //4.     public void setOnCheckedChangeListener(OnCheckedChangeListener listener) {    mOnCheckedChangeListener = listener;    }
Global exception Handling
  • Method defines the place. Uniform throw base class

    /** *  这个是一个会抛出异常b的方法 * @throws HMException * @throws HMException */public static void methodB() throws HMException {    //如果在某一个时刻.出现了异常啊.    //出现状态的是子类.抛出的是父类.    throw new HMBException();//主动抛异常}
  • Where the method is used, the try catch base class

    try {            Api.methodB();        } catch (HMException e) {            handleException(e);}
  • Hint Information materialized

    /** * 不同异常子类用不同的code表示 * @param e * @return */public static int exception2code(HMException e) {int errCode = 0;if (e instanceof HMAException) {    errCode = 1;} else if (e instanceof HMBException) {    errCode = 2;} else if (e instanceof HMCException) {    errCode = 3;} else if (e instanceof HMDException) {    errCode = 4;}return errCode;}/** * 根据不同的异常信息.显示不同的效果 * @param e */public void handleException(HMException e) {    int exception2code = ExceptionHandler.exception2code(e);    String code2String = ExceptionHandler.code2String(exception2code);    Toast.makeText(getApplicationContext(), code2String, 0).show();}
Actionbarsherlock

Actionbar version Compatibility Library. We can use the Actionbar under 2.1.

    actionBar = getSupportActionBar();//得到actionbar,    actionBar.setDisplayHomeAsUpEnabled(true);//是否显示返回箭头,默认情况是false,    //如果setDisplayShowHomeEnabled setDisplayShowTitleEnabled 都是false,那么退回图标设置为true/false都不见    actionBar.setDisplayShowHomeEnabled(false);//是否显示logo,默认是true    actionBar.setDisplayShowTitleEnabled(true);//是否显示title,默认是true    //      actionBar.setTitle("56期");//修改title    //      actionBar.setIcon(R.drawable.icon_download);//修改logo
The difference between several actionbar
    • Actionbarsherlock->actionbar--> support-->2.1 The following systems also have to be used, Actionbarsherlock provides a lot of styles;
    • The system above v7-->actionbar-->2.1 can support
    • Android sdk->actionbar-->3.0 above phone support
V4 V7 V13
    • V4: Compatible with API Level4 (Android 1.6)
    • V7: Compatible with API Level7 (Android 2.1)
    • V13: Compatible with API Level3 (Android 3.2)
QR code, historic stuff.

Using the zxing package, QRCode

The simplification of two-dimensional code

It was a long time ago. The simplification of the zxing package is a comparison of fire.

Two-dimensional code and screen switching

The picture is cut sideways

Two-dimensional code animation

Imitation Scan effect

Using zxing to scan two-dimensional code to understand two-dimensional code
    • The range of the QR code
    • Two-dimensional code fault tolerance level
    • Two-dimensional Code embedded logo
Use the Find button first and then call
1. Start the scanning interface Intent Intent = new Intent (mainactivity.this, Captureactivity.class); Startactivityforresult (Intent, scannin_grequest_code);//2. Processing Scan Results/** * * @param result * @param barcode */public void Han    Dledecode (result result, Bitmap barcode) {inactivitytimer.onactivity ();    Playbeepsoundandvibrate ();    Scan result String resultstring = Result.gettext ();    if (Resultstring.equals (")") {Toast.maketext (Captureactivity.this, "Scan failed!", Toast.length_short). Show ();        } else {//2. Pass the scan result Intent resultintent = new Intent ();        Bundle bundle = new bundle ();        Bundle.putstring ("result", resultstring);        Bundle.putparcelable ("Bitmap", barcode);        Resultintent.putextras (bundle);    This.setresult (RESULT_OK, resultintent); } CaptureActivity.this.finish ();} 3. Results of receiving callbacks @overrideprotected void Onactivityresult (int requestcode, int resultcode, Intent data) {Super.onactivityre  Sult (Requestcode, ResultCode, data);  Switch (requestcode) {case Scannin_grequest_code:if (ResultCode = = RESULT_OK) {Bundle bundle = d            Ata.getextras ();            Displays the contents of the scan Tv_result.settext (bundle.getstring ("result"));        Show Iv_qrcode.setimagebitmap ((Bitmap) Data.getparcelableextra ("Bitmap"));    } break; }}
Friends Leaguemulti-channel packaging can be UF tools, ant, Gradle

2. Drop-down refresh, two-dimensional code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.