android 通用view封装
来源:互联网 发布:linux 套接字文件 编辑:程序博客网 时间:2024/05/18 16:39
<pre style="background-color: rgb(255, 255, 255); font-family: 'Courier New'; font-size: 15pt;"><span style="color: rgb(0, 0, 128);"><strong>分装某个view 实现通用界面和点击事件等</strong></span>
public class PayResultView extends RelativeLayout { private Context context; private ImageView logo; private TextView pay_result_tips; private TextView company_phone; private Button confirm; private TextView worktime; private String ok_tips; private String worktime_tips; private String company_phone_tips; private String error_tips; private String def_work_week = "周一至周五"; private String def_work_time = "9:00-18:00"; private String def_phont_number = "010-53317783"; public PayResultView(Context context) { super(context); init(context); } public PayResultView(Context context, AttributeSet attrs) { super(context, attrs); init(context); } public PayResultView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(context); } private void init(Context context) { this.context = context; LayoutInflater.from(context).inflate(R.layout.pay_result, this, true); logo = (ImageView) findViewById(R.id.pay_result_logo); confirm = (Button) findViewById(R.id.confirm_pay); worktime = (TextView) findViewById(R.id.work_time); company_phone = (TextView) findViewById(R.id.company_phone); pay_result_tips = (TextView) findViewById(R.id.pay_result_tips); ok_tips = context.getResources().getString(R.string.pay_result_ok_tips); error_tips = context.getResources().getString(R.string.pay_result_error_tips); company_phone_tips = context.getResources().getString(R.string.pay_result_connect); worktime_tips = context.getResources().getString(R.string.pay_result_worktime); getCompanyInfo(); } private void getCompanyInfo() { HttpUtils httpUtils = new HttpUtils(); httpUtils.send(HttpRequest.HttpMethod.GET, URLs.SERVICE_INFO, new RequestCallBack<String>() { @Override public void onSuccess(ResponseInfo<String> responseInfo) { ResultBean resultBean = JSON.parseObject(responseInfo.result, ResultBean.class); if (null != resultBean && ResultBean.STATUS_SUCCESS.equals(resultBean.http_status)) { try { JSONObject object = new JSONObject(resultBean.data); String work_week = (String) object.get("work_week"); String phone_number = (String) object.get("phone_number"); String work_time = (String) object.get("work_time"); setInfo(work_week, phone_number, work_time); } catch (JSONException e) { LogUtils.e("text", "JSONException in parseing servicesinfo"); setInfo(def_work_week, def_phont_number, def_work_time); } } } @Override public void onFailure(HttpException e, String s) { setInfo(def_work_week, def_phont_number, def_work_time); } }); } private void setInfo(String work_week, String phone_number, String work_time) { company_phone.setText(String.format(company_phone_tips, phone_number)); worktime.setText(String.format(worktime_tips, new StringBuffer(work_week).append(" ").append(work_time).toString())); } /** * 设置支付结果 * * @param money 如果支付成功,把金额以字符串形式传进来,失败则填null * @param success 支付成功true,失败false */ public void setResult(String money, boolean success) { if (success) { logo.setBackgroundResource(R.drawable.confirm_green); pay_result_tips.setText(String.format(ok_tips, money)); } else { logo.setBackgroundResource(R.drawable.icon_fail); pay_result_tips.setText(error_tips); } } /** * 设置点击事件 * * @param listener */ public void setButtonClicklistenter(View.OnClickListener listener) { confirm.setOnClickListener(listener); }}
0 0
- android 通用view封装
- Android 通用Adapter封装
- android 一些通用View
- Android 通用网络框架封装
- android通用适配器的封装
- Android RecyclerView通用Adapter封装
- android 封装一个view模块
- Android异步请求通用封装类
- Android 通用标题栏简单封装实现
- Android 封装一个通用的PopupWindow
- Android 封装一个通用的PopupWindow
- Android 自定义通用Dialog的封装
- Android自定义View之TitleBar,通用标题栏
- android 一些通用view(2)
- android view手势冲突的通用解决方法
- android view手势冲突的通用解决方法
- Android通用框架封装一 数据中心DataCenter框架封装
- Android通用框架封装二 Log日志框架封装
- JavaScript拖动层Div代码
- C#与Java的比较
- CSS字体选择,字体大小,粗细,斜体,缩进,文字单词间距
- android的消息传递简单实例
- Android 下获取所有应用的流量使用量
- android 通用view封装
- json串中English("")换成Chinese(“”)函数代码
- 天涯明月刀 题七
- 天声人語 20151229 巨大グラブで夢をつかむ
- 微软的Live SDK各个API简介
- GitHub控件之BadgeView(数字提醒)
- Java工程师成神之路
- 日经春秋 20151229
- eclipse上Git的安装和使用