小知识点

来源:互联网 发布:网络问政直通车 编辑:程序博客网 时间:2024/06/05 16:02


1 获得系统时间

SimpleDateFormat formatter = new SimpleDateFormat ("HHmmss ");
Date curDate = new Date(System.currentTimeMillis());//获取当前时间
String str = formatter.format(curDate);
System.out.println("time :"+str);

2 格式化输出
String strings = String.format("0%s", 2);
System.out.println(strings);

3 时间格式转换

public static void main(String[] args) {

// TODO Auto-generated method stub
String str = "2013-01-21 15:10:20";  
       Date date = null;  
       SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd-HH:mm:ss");  
       try {  
           date = sdf.parse(str);
       } catch (ParseException e) {  
           System.out.println(e.getMessage());  
       }  
       System.out.println(date);  
       System.out.println(date.getTime());  
   }  

4 一句话得到时间

System.out.println(""+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));

4 获得日期

Date now = new Date();
        CharSequence dow = DateFormat.format("EEEE", now);// EEEE 显示为"星期4"  E  EE  EEE 都显示为“周四”
        CharSequence date = DateFormat.getLongDateFormat(this).format(now);// "2015年01月01日"
        Toast.makeText(this, ""+dow, Toast.LENGTH_LONG).show();

5 创建简单适配器

adapter = new SimpleAdapter(MainActivity.this, oList,
R.layout.listview_item, new String[] { "id_",
"classname_", "classtype_" }, new int[] {
R.id.item_id, R.id.item_classname,
R.id.item_classtype });
listview.setAdapter(adapter);


6 string array

<resources>


    <string name="app_name">SqliteDateBase_Test</string>
    <string name="action_settings">Settings</string>
    <string name="hello_world">Hello world!</string>


    <string-array name="dialog_array">
        <item>更改</item>
        <item>删除</item>
    </string-array>


</resources>

<pre name="code" class="cpp">listview.setOnItemLongClickListener(new OnItemLongClickListener() {public boolean onItemLongClick(AdapterView<?> parent, View view,final int position, long id) {Map<String, Object> map = (Map<String, Object>) listview.getItemAtPosition(position);index = map.get("id_").toString();AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);builder.setTitle("请选择");builder.setItems(R.array.dialog_array, // ******** 此处引用string arraynew DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog,int which) {switch (which) {case 0:LayoutInflater inflater = getLayoutInflater().from(MainActivity.this);View view = inflater.inflate(R.layout.dialog_item, null);final EditText dialog_classname = (EditText) view.findViewById(R.id.dialog_classname);final EditText dialog_classtype = (EditText) view.findViewById(R.id.dialog_classtype);AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);builder.setTitle("请更改");builder.setView(view);builder.setPositiveButton("确定",new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog,int which) {SQLitedatabaseUtil.update(db,dialog_classname.getText().toString(),dialog_classtype.getText().toString(),index);oList.get(position).put("classname_",dialog_classname.getText().toString());oList.get(position).put("classtype_",dialog_classtype.getText().toString());adapter.notifyDataSetChanged();}});builder.setNegativeButton("取消",new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog,int which) {}});builder.show();Toast.makeText(MainActivity.this, "点击了更改",Toast.LENGTH_SHORT).show();break;case 1:SQLitedatabaseUtil.delete(db, index);oList.remove(position);adapter.notifyDataSetChanged();break;default:break;}}});builder.show();return false;}});


7 动画的加载

rotatl.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <rotate
        android:duration="500"
        android:fromDegrees="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:repeatCount="infinite"
        android:toDegrees="359"/>
</set>


private void initAnim() {
anim = AnimationUtils.loadAnimation(this, R.anim.rotate);
LinearInterpolator linearInterpolator = new LinearInterpolator();
anim.setInterpolator(linearInterpolator);
}


refresh.startAnimation(anim); // refresh 是一个图片 是让这个图片旋转

                                             
0 0
原创粉丝点击