Android工具类

来源:互联网 发布:推荐les淘宝店 编辑:程序博客网 时间:2024/06/05 22:56
import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date;import android.os.Handler;import android.text.TextUtils;import android.view.View;import android.widget.AbsListView;import android.widget.TextView;import com.sinolbs.ecd.R;public class CommonUtils {public static String getAgeByDateTime(String dateTime) {String year = null;SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");  java.util.Date date=new Date();       java.util.Date mydate;try {mydate = myFormatter.parse(dateTime);long day=(date.getTime()-mydate.getTime())/(24*60*60*1000) + 1;year=new java.text.DecimalFormat("#").format(day/365f);} catch (ParseException e) {e.printStackTrace();}return year;}/** * 将字符串时间转换为毫秒值 * @param str * @return */public static long getTimeStemp(String str){        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");        Date d = null;        try {        if (!TextUtils.isEmpty(str)) {        d = sdf.parse(str);        return d.getTime();}        } catch (ParseException e) {            e.printStackTrace();        }                return 0;    }public static void setCollTextBg(TextView item_constellation , String constellation){//改变背景的颜色if ("白羊座".equals(constellation)) {item_constellation.setBackgroundResource(R.color.baiyang);}else if ("金牛座".equals(constellation)) {item_constellation.setBackgroundResource(R.color.jinniu);}else if ("双子座".equals(constellation)) {item_constellation.setBackgroundResource(R.color.shuangzi);}else if ("巨蟹座".equals(constellation)) {item_constellation.setBackgroundResource(R.color.juxie);}else if ("狮子座".equals(constellation)) {item_constellation.setBackgroundResource(R.color.shizi);}else if ("处女座".equals(constellation)) {item_constellation.setBackgroundResource(R.color.chunv);}else if ("天秤座".equals(constellation)) {item_constellation.setBackgroundResource(R.color.tiancheng);}else if ("天蝎座".equals(constellation)) {item_constellation.setBackgroundResource(R.color.tianxie);}else if ("射手座".equals(constellation)) {item_constellation.setBackgroundResource(R.color.sheshou);}else if ("摩羯座".equals(constellation)) {item_constellation.setBackgroundResource(R.color.mojie);}else if ("水瓶座".equals(constellation)) {item_constellation.setBackgroundResource(R.color.shuiping);}else if ("双鱼座".equals(constellation)) {item_constellation.setBackgroundResource(R.color.shuangyu);}else {item_constellation.setVisibility(View.GONE);}}public static void scrollToListviewTop(final AbsListView listView){        listView.smoothScrollToPosition(0);        final Handler handler = new Handler();        handler.postDelayed(new Runnable()        {            @Override            public void run()            {                if (listView.getFirstVisiblePosition() > 0)                {                    //listView.smoothScrollToPosition(0);                listView.setSelection(0);                    handler.postDelayed(this, 100);                }            }        }, 100);    }}

0 0
原创粉丝点击