复习代码

1、定时器与handler配合使用:

    @SuppressLint("HandlerLeak")
    private void setTimer() {

        timer = new Timer();
        handler = new Handler() {

            @Override
            public void handleMessage(Message msg) {

                request();
                super.handleMessage(msg);
            }
        };
        TimerTask task = new TimerTask() {

            @Override
            public void run() {

                Message message = new Message();
                message.what = 1;
                handler.sendMessage(message);
            }
        };
        timer.schedule(task, 10000, 10000);
    }

最后关闭Activity时应取消定时器

    public void onDestroy() {

        super.onDestroy();

        if (timer != null){

            timer.cancel();
        }
    }

2、各种文件格式打开

// 打开
    private void OpenFile() {

        m_pDialog.cancel();

        String end = fileName.substring(fileName.lastIndexOf(".") + 1,
                fileName.length()).toLowerCase();

        Intent intent = new Intent(Intent.ACTION_VIEW);

        if (end.equals("jpg") || end.equals("gif") || end.equals("png")
                || end.equals("jpeg") || end.equals("bmp")) {

            intent.setDataAndType(
                    Uri.fromFile(new File(Environment
                            .getExternalStorageDirectory() + "/wzh/",
                            fileName)), "image/*");

        } else if (end.equals("doc") || end.equals("docx")) {

            intent.setDataAndType(
                    Uri.fromFile(new File(Environment
                            .getExternalStorageDirectory() + "/wzh/",
                            fileName)), "application/msword");

        } else if (end.equals("xls") || end.equals("xlsx")) {

            intent.setDataAndType(
                    Uri.fromFile(new File(Environment
                            .getExternalStorageDirectory() + "/wzh/",
                            fileName)), "application/vnd.ms-excel");

        } else if (end.equals("ppt") || end.equals("pptx")) {

            intent.setDataAndType(
                    Uri.fromFile(new File(Environment
                            .getExternalStorageDirectory() + "/wzh/",
                            fileName)), "application/vnd.ms-powerpoint");

        } else if (end.equals("chm")) {

            intent.setDataAndType(
                    Uri.fromFile(new File(Environment
                            .getExternalStorageDirectory() + "/wzh/",
                            fileName)), "application/x-chm");

        } else if (end.equals("tif")) {

            intent.setDataAndType(
                    Uri.fromFile(new File(Environment
                            .getExternalStorageDirectory() + "/wzh/",
                            fileName)), "image/tiff");

        } else if (end.equals("txt")) {

            intent.setDataAndType(
                    Uri.fromFile(new File(Environment
                            .getExternalStorageDirectory() + "/wzh/",
                            fileName)), "text/plain");

        } else if (end.equals("pdf")) {

            intent.setDataAndType(
                    Uri.fromFile(new File(Environment
                            .getExternalStorageDirectory() + "/wzh/",
                            fileName)), "application/pdf");

        } else if (end.equals("zip")) {

            intent.setDataAndType(
                    Uri.fromFile(new File(Environment
                            .getExternalStorageDirectory() + "/wzh/",
                            fileName)), "application/zip");
        } else {
            intent.setDataAndType(
                    Uri.fromFile(new File(Environment
                            .getExternalStorageDirectory() + "/wzh/",
                            fileName)), "*/*");
        }

        startActivity(intent);
    }

3、PagerSlidingTabStrip与ViewPager、Fragment

 

    <com.astuetz.PagerSlidingTabStrip
        android:id="@+id/tab"
        android:layout_width="match_parent"
        android:layout_height="36dp"
        android:fillViewport="false"
        app:pstsIndicatorHeight="0dp"
        app:pstsShouldExpand="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true" />
//占满整行 
app:pstsShouldExpand="true"

 

 

        vpSlide = (ViewPager) findViewById(R.id.vpSlide);

        fragmentList = new ArrayList<>();
        fragmentList.add(new Frag1());
        fragmentList.add(new Frag2());
        fragmentList.add(new Frag3());

        vpSlide.setAdapter(new PagerSlideAdapter(this.getSupportFragmentManager(), fragmentList, title));
        tab = (PagerSlidingTabStrip) findViewById(R.id.tab);
        tab.setViewPager(vpSlide);
        tab.setDividerColor(Color.TRANSPARENT);//每个标签的分割线的颜色
        tab.setTextColor(Color.parseColor("#FE0000"));
        tab.setIndicatorColor(Color.parseColor("#FE0000")); //滑动条的颜色
        tab.setIndicatorHeight((int) 5); //滑动条的高度
        tab.setUnderlineColor(Color.TRANSPARENT); //滑动条所在的那个全宽线的颜色
        tab.setShouldExpand(true); //设置为true表示每个标签是相同的控件,均分整个屏幕,默认是false

 

public class PagerSlideAdapter extends FragmentStatePagerAdapter {

    //注意需要把FragmentPagerAdapter 改为 FragmentStatePagerAdapter,不然卡顿和无法显示
    List<Fragment> list;
    String[] title;

    public PagerSlideAdapter(FragmentManager fm, List<Fragment> list, String[] title) {
        super(fm);
        this.list = list;
        this.title = title;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        Fragment fragment = (Fragment) object;
    }

    @Override
    public Fragment getItem(int position) {
        return list.get(position);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == ((Fragment) object).getView();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return title[position];
    }

}

 4、每周一答(稍后看)

 

posted @ 2017-05-22 13:36  ChHM  阅读(194)  评论(0编辑  收藏  举报