燃气安检

如何将id值转化成颜色值

 public static int getResColor(int resid)
    {
        Resources rs = ServiceApplication.getInstance().getResources();
        return rs.getColor(resid);
    }

mButtonLeft.setTextColor(PublicUtil.getResColor(R.color.app_color));
mLinearTitleContent.setBackgroundColor(PublicUtil.getResColor(R.color.title_color));

android 控件位置的xml属性

android:sigleLine 如果设置为真的话,则控件的内容在同一行中进行显示。    
 android:scaleType 是控制图片如何   
 resized/moved来匹配ImageView的size。    
 android:hint 设置EditText为空时输入框内的提示信息。    
 android:LinearLayout 它确定了LinearLayout的方向,其值可以为vertical,   


android:gravity 指定View组件的对齐方式,比如说居中、居右等,这里指的是   
android:layout_gravity(区别于:android:gravity ) 指定Container组件的对   


android:layout_centerHrizontal 当前控件位于父控件的横向中间位置(水平   
android:layout_centerVertical 当前控件位于父控件的竖向中间位置(垂直方   
android:layout_centerInparent 相对于父控件完全居中。

android:layout_alignParentBottom 当前控件低端与父控件的低端对齐。
android:layout_alignParentLeft 当前控件左边缘与父控件的左边缘对齐。 
android:layout_alignParentRight 当前控件右边缘端与父控件的右边缘对齐。   
android:layout_alignParentTop 当前控件顶端与父控件的顶端对齐。
android:layout_alignWithParentIfMissing 如果对应的兄弟元素找不到的话就   

android:layout_below 使当前控件位于给出id控件的下方。
android:layout_above 使当前控件位于给出id控件的上方。 
android:layout_toLeftOf 使当前控件位于给出id控件的左边。 
android:layout_toRightOf 使当前控件位于给出id控件的右边。

android:layout_alignTop 本控件的上边缘和某控件的的上边缘对齐。 
android:layout_alignLeft 本元素的左边缘和某元素的的左边缘对齐。 
android:layout_alignBottom 本元素的下边缘和某元素的的下边缘对齐。 
android:layout_alignRight 本元素的右边缘和某元素的的右边缘对齐。

android:layout_margin 设置控件到相邻控件或者边缘的距离(上下左右)。 
android:layout_marginBottom 设置控件到相邻控件底边缘的距离。 
android:layout_marginLeft 设置控件到相邻控件左边缘的距离。 
android:layout_marginRight 设置控件到相邻控件右边缘的距离。 
android:layout_marginTop 设置控件到相邻控件上边缘的距离。

android:padding 设置控件的内容在4个方向距离控件边缘的距离,指定控件的   
android:paddingLeft 控件内容离本控件右边缘的距离。 
android:paddingRight 本控件内容离本控件上边缘的距离。

二。

属性 值 说明   
android:orientation horizontal/vertical 设置布局水平还是垂直,默认是垂   
android:checked true/false 标记默认选中,如果是单选则选中最后一个 
android:layout_gravity center/right/left/bottom/top 
 android:gravity center/right/left/bottom/top 
android:gravity属性是对该view内容的限定.比如一个button上面的text   
android:layout_gravity是用来设置该view相对与起父view的位置.比如一个bu   
android:hint @string 提示信息,当文本框为空的时候显示
android:numeric integer/decimal 只能输入整数/小数 
android:singleLine true/false 设置单行输入,一旦设置为true,则文字不会   
android:password true/false 设置密码框
android:textColor

Android Activity 四种启动模式的区别

1、standard标准模式
    发现每次都创建了Activity2的新实例。standard的加载模式就是这样的,Intent将发送给它新的Activity实例
2、 singleTop
不过,singleTop要求如果创建intent时栈顶已经有要创建Activity的实例,则将Intent发送给该实例,而不发送给新的实例。
  android:launchMode="singleTop"
3、singleTask
singleTask模式和后面的singleInstance模式都是只创建一个实例的。
当Intent到来,需要创建singleTask模式Activity时,系统会检查栈里面是否已经有该Activity的实例。如果有直接将Intent发送给它(注意此时原在此Activity栈中上面的Activity将会被关闭)。
   android:launchMode="singleTask"
4、singleInstance
   在singleInstance模式下,加载该Activity时如果没有实例化,它会在创建新的Task后,实例化入栈,如果已经存在,则直接调用onNewIntent,该Activity的Task中不允许启动其他的Activity,任何从该Activity启动的其他Activity都将被放到其他Task中,先检查是否有在应用的Task,没有的话就创建。
   android:launchMode="singleInstance"

健康助手首页布局的做法

采用了两个线性布局,中间在用线性布局来包裹一个图片和文字的做法
<LinearLayout
        android:id="@+id/l1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:orientation="horizontal" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal" 内容水平居中
            android:orientation="vertical" >

            <ImageButton
                android:id="@+id/tv_ele"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:background="#FFFFFF"
                android:scaleType="fitXY"
                android:src="@drawable/ic_elem" />

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="电子病历" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp"
            android:gravity="center_horizontal"
            android:orientation="vertical" >

            <ImageButton
                android:id="@+id/tv_med"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:background="#FFFFFF"
                android:scaleType="fitXY"
                android:src="@drawable/ic_med" />

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="提醒助手" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:orientation="vertical" >

            <ImageButton
                android:id="@+id/tv_sp"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:background="#FFFFFF"
                android:scaleType="fitXY"
                android:src="@drawable/ic_sport" />

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="锻炼管理" />
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/l2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:gravity="center_horizontal"
        android:orientation="horizontal" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="30dp"
            android:gravity="center_horizontal"
            android:orientation="vertical" >

            <ImageButton
                android:id="@+id/tv_pic"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:background="#FFFFFF"
                android:scaleType="fitXY"
                android:src="@drawable/ic_tpic2" />

            <TextView
                android:id="@+id/textView4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="图片文件" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:orientation="vertical" >

            <ImageButton
                android:id="@+id/tv_clube"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:background="#FFFFFF"
                android:scaleType="fitXY"
                android:src="@drawable/ic_clube" />

            <TextView
                android:id="@+id/textView5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="病友圈" />
        </LinearLayout>
    </LinearLayout>

xUtils-2.6.14.jar 包的网络图片显示策略

 import com.lidroid.xutils.BitmapUtils;

BitmapUtils bitmapUtils = new BitmapUtils(context);
bitmapUtils.display(holder.infoImage,ConnectUtil.HOST_URL + item.image);

标准的json字符串

{
    "datas": [
        {
            "age": 0,
            "age2": 0,
            "age3": 0,
            "gcategory": [
                {
                    "cateId": 1398,
                    "cateName": "餐饮/卤菜",
                    "imageApp": "/app_res/category_img/keeping.png"
                },
                {
                    "cateId": 1324,
                    "cateName": "蔬菜/水果/肉类/鱼",
                    "imageApp": "/app_res/category_img/fruits_meat.png"
                }
            ],
            "phoneNum": "1354545"
        },
        {
            "age": 0,
            "age2": 0,
            "age3": 0,
            "phoneNum": "1354545"
        },
        {
            "age": 0,
            "age2": 0,
            "age3": 0,
            "phoneNum": "1354545"
        }
    ],
    "limit": 0,
    "msg": "查询成功!",
    "start": 0,
    "success": true,
    "total": 2
}

利用gson将json字符串解析成对象

  package com.example.administrator.xuanxiangka;

import java.io.Serializable;

@SuppressWarnings("serial")
public class ZiXun implements Serializable {

    //json的语法规则 字符串用双引号括起来  数字不要用双引号

    //json赋值是这个变量对应的值也要是数字 负责无法解析
    public int   id;
    public String newId;  //new 获取id
    public String title;
    public String image;
    public String time;
    public String videoUrl;
    public String content;  //点击详细信息xml
    public String contentRead;
    public String good;  //点赞次数
    public String house; //收藏  0为未收藏, 1为收藏
    public String type;  //用于详细页判断, 咨询跟说明书

    public static final String TYPE_ZIXUN ="zixun";
    public static final String TYPE_EXPLAIN ="explain";

    @Override
    public String toString() {
        return "ZiXun{" +
                "id=" + id +
                ", newId='" + newId + '\'' +
                ", title='" + title + '\'' +
                ", image='" + image + '\'' +
                ", time='" + time + '\'' +
                ", videoUrl='" + videoUrl + '\'' +
                ", content='" + content + '\'' +
                ", contentRead='" + contentRead + '\'' +
                ", good='" + good + '\'' +
                ", house='" + house + '\'' +
                ", type='" + type + '\'' +
                '}';
    }
}

导入gson的解析方法

这两个方法的引用需要导入gson-2.2.4.jar才可以引用
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

JSONObject jsonObject;
        Type type = new TypeToken<List<ZiXun>>() {
        }.getType();

        try {
            jsonObject = new JSONObject(data);//把字符串转化成一个json对象
            if ("true".equals(jsonObject.getString("success"))) {            
                Gson gson = new Gson();

            //利用gson把对象解析成泛型
                T obj = gson.fromJson(jsonObject.getString("data"), type);
             //泛型强制转化成对象的集合
                List<ZiXun> tan =(List<ZiXun>)obj;    
                //打印结果
                for(ZiXun g:tan){
                    Log.d("tanyinqing这似乎结果","这似乎结果"+g.toString()); //过滤注释的方法                                }
                //对结果进行回调
                //listener.onSuccess(obj); 
                //listener.onFailed(obj);
            } else {
            // 网络访问数据获取失败 弹出提示信息
                    switch (serviceApplication.mPrefUtil.getIntSetting("tiShi")){
                    case 0:
                        PublicUtil.ShowToast("访问网络失败,请重新访问");
                        serviceApplication.mPrefUtil.putSetting("tiShi",10);
                        break;
                    default:
                        //PublicUtil.ShowToast("" + jsonObject.getString("msg"));
                        break;
                }
            //listener.onFailed();

        } catch (Exception e) {
        //这是对异常的处理 或土司或回调或弹出框或打印日志
            /*listener.onFailed();
            PublicUtil.ShowToast("" + e.toString());
            Log.e(TAG, "json parse failed : " + e.toString());
            PromptManager.showDialogTest1(mContext, "解析失败,弹出解析失败的原因 : " + e.toString());*/
            e.printStackTrace();
        }

要解析成对象的对应的json数据

   {
    "data": [
        {
            "content": 33,
            "contentRead": 33,
            "good": "dfdsa",
            "house": 4,
            "id": 33,
            "image": 33,
            "newId": 33,
            "time": 33,
            "title": 33,
            "type": 44,
            "videoUrl": 33
        },
        {
            "content": "tan",
            "contentRead": "tan",
            "good": "tan",
            "house": "tan",
            "id": 44,
            "image": "tan",
            "newId": "tan",
            "time": "tan",
            "title": "tan",
            "type": "tan",
            "videoUrl": "tan"
        }
    ],
    "limit": 0,
    "msg": "查询成功!",
    "start": 0,
    "success": true,
    "total": 2
}

从json字符串到对象集合再到list列表的过程

 public TaskListAdapter getGoodsAdapter() {
        JSONObject jsonObject;
        List<TaskListEntity> list=new ArrayList<>();
        Type type = new TypeToken<List<TaskListEntity>>() {
        }.getType();
        try {
         //把字符串转化成一个json对象
            jsonObject = new JSONObject(dataAppUtil.TaskListData);
            if ("true".equals(jsonObject.getString("success"))) {
                Gson gson = new Gson();
                T obj = gson.fromJson(jsonObject.getString("data"), type);
                list =(List<TaskListEntity>)obj;
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
         mGoodsAdapter.appendToListAndClear(list);
        return mGoodsAdapter;
    }

results matching ""

    No results matching ""