标签:
#项目简介在这个页面中,若用户未登录,则在该页面最上方会提示:您还未登录”同时在右上角会有一个登陆按钮,通过点击该按钮可跳转至登陆页面。在交易页面,有充值、快速提现、查询等操作。
private class MySpinnerAdapter extends BaseAdapter implements SpinnerAdapter { @Override public int getCount() { return mListData.size(); } @Override public Object getItem(int position) { return mListData.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = LayoutInflater.from(context).inflate(R.layout.my_simple_spinner_item_recharge, null); } TextView view = (TextView) convertView .findViewById(R.id.recharge_spinner_view); view.setText(mListData.get(position).getName()); if (mListData.get(position).getSupport_withhold() == 1) { view.setEnabled(true); } else { view.setEnabled(false); } return convertView; } @Override public View getDropDownView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = LayoutInflater.from(context).inflate(R.layout.my_simple_spinner_dropdown_item_recharge, null); } CheckedTextView view = (CheckedTextView) convertView.findViewById(R.id.recharge_spinner_item); view.setText(mListData.get(position).getName()); if (mListData.get(position).getSupport_withhold() == 1) { view.setEnabled(true); view.setCompoundDrawablesWithIntrinsicBounds(null, null, getResources().getDrawable(R.drawable.icon_withhold), null); } else { view.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null); view.setEnabled(false); } return convertView; } }
/** * 获取帮助消息 */ private Handler getHelpsHandler = new Handler() { public void handleMessage(Message msg) { dismissProgressDialog(); switch (msg.what) { case BaseHandlerUI.TASK_NOTIFY_RETURN_DATA: if (msg.obj != null) { try { bean = (GetHelpsResultBean) msg.obj; if (bean.state.equals("0")) { mDatabaseAdapter.open_fund(); mDatabaseAdapter.deleteAllHelpsData(); List<TreeViewAdapter.TreeNode> treeNode = adapter.GetTreeNode(); treeNode.clear(); for (int i = 0; i < bean.list.size(); i++) { mDatabaseAdapter.insertHelpsData(bean.list.get(i).ask, bean.list.get(i).reply); TreeViewAdapter.TreeNode node = new TreeViewAdapter.TreeNode(); node.parent = bean.list.get(i).ask; for (int ii = 0; ii < 1; ii++) { node.childs.add(bean.list.get(i).reply); } treeNode.add(node); } adapter.UpdateTreeNode(treeNode); expandableList.setAdapter(adapter); mDatabaseAdapter.close_funds(); } } catch (Exception e) { e.printStackTrace(); } } else { } break; } } };
<span style="font-size:18px;">class DownloadTask extends AsyncTask<Void,Integer,Boolean>{}</span>
public HttpRequestAsyncTask(HttpRequestInfo request, TaskListener listener, Context context) { this.context = context; request.putParam("device_info", ConfigUtil.getImei(context)) .putParam("app_version", ConfigUtil.getVersionName(context)) .putParam("market", context.getString(R.string.channel_str)); mListener = listener; mRequest = request; } public HttpRequestAsyncTask(HttpRequestInfo request, TaskListenerWithState taskListenerWithState, Context context) { this.context = context; request.putParam("device_info", ConfigUtil.getImei(context)) .putParam("app_version", ConfigUtil.getVersionName(context)) .putParam("market", context.getString(R.string.channel_str)); mListenerWithState = taskListenerWithState; mRequest = request; } @Override protected HttpResponseInfo doInBackground(Void... params) { if (!ConfigUtil.isConnect(context)) { return new HttpResponseInfo(null, HttpTaskState.STATE_NO_NETWORK_CONNECT); } try { if (mRequest != null) { if (mRequest.getRequestID() == -2) { return new HttpResponseInfo( HttpManager.postHttpRequest(mRequest), HttpTaskState.STATE_OK); } return new HttpResponseInfo( HttpManager.postHttpsRequest(mRequest), HttpTaskState.STATE_OK); } } catch (SocketTimeoutException e) { e.printStackTrace(); return new HttpResponseInfo("{\"result\":\"3\"}", HttpTaskState.STATE_OK); } catch (UnknownHostException e) { e.printStackTrace(); return new HttpResponseInfo("{\"result\":\"3\"}", HttpTaskState.STATE_OK); } catch (Exception e) { e.printStackTrace(); return new HttpResponseInfo("{\"result\":\"3\"}", HttpTaskState.STATE_OK); } return null; }
#HTTP编程
Http编程有请求和响应,这里我们把对json数据年度解析放到这一部分来讲解:
/** * Http 请求 */ public class HttpRequestInfo { public static final String TAG = "HttpRequestInfo"; /* Http 请求的 URL */ private String requestUrl; private int requestID; private Map<String, String> requestParams; public HttpRequestInfo(String url) { this.setRequestUrl(url); requestParams = new HashMap<String, String>(); } public HttpRequestInfo(String url, Map<String, String> params) { this.setRequestUrl(url); this.setRequestParams(params); } public String getRequestUrl() { return requestUrl; } public void setRequestUrl(String requestUrl) { this.requestUrl = requestUrl; } public Map<String, String> getRequestParams() { return requestParams; } public void setRequestParams(Map<String, String> requestParams) { this.requestParams = requestParams; } public String getParamsStr() { String str = ""; if (requestParams != null) { for (Entry<String, String> entry : requestParams.entrySet()) { String key = entry.getKey(); String val = entry.getValue(); key = URLEncoder.encode(key); val = URLEncoder.encode(val); str += key + "=" + val + "&"; } } if (str.equals("")) { return null; } LogUtil.i(TAG, this.requestUrl + str); return str; } public HttpRequestInfo putParam(String key, String value) { this.requestParams.put(key, value); return this; } public int getRequestID() { return requestID; } public void setRequestID(int requestID) { this.requestID = requestID; } }对于响应:
/** * Http 响应 */ public class HttpResponseInfo { public enum HttpTaskState { STATE_OK, STATE_NO_NETWORK_CONNECT, STATE_TIME_OUT, STATE_UNKNOWN, } public HttpResponseInfo(String result, HttpTaskState state) { this.result = result; this.state = state; } private HttpTaskState state; private String result; public HttpTaskState getState() { return state; } public void setState(HttpTaskState state) { this.state = state; } public String getResult() { return result; } public void setResult(String result) { this.result = result; } }
SQLiteOpenHelper有onCreate()、onUpgrade()两个方法。
private static class DatabaseHelper extends SQLiteOpenHelper { public DatabaseHelper(Context context, String name, CursorFactory factory, int version) { super(context, DB_NAME, null, version); } @Override public void onCreate(SQLiteDatabase db) { //创建所有数据库表 db.execSQL(DB_CREATE_FUND); db.execSQL(DB_CREATE_FAV_FUND); db.execSQL(DB_CREATE_HELPS_INFO); db.execSQL(DB_CREATE_FUND_DETAIL); db.execSQL(DB_CREATE_MSG); } // 更新基金数据 @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS " + DB_TABLE_FUND); db.execSQL("DROP TABLE IF EXISTS " + DB_TABLE_FAV_FUND); db.execSQL("DROP TABLE IF EXISTS " + DB_CREATE_HELPS_INFO); db.execSQL("DROP TABLE IF EXISTS " + DB_CREATE_FUND_DETAIL); db.execSQL("DROP TABLE IF EXISTS " + DB_CREATE_MSG); onCreate(db); } }
当然了,仅仅通过一篇博文是不可逆完全完整的说完整个项目了,这里写的仅仅是冰山一角,更多的内容还是希望读者自己去发现并学到里面的精华部分!当然咯,我相信有一部分人读了也基本上没看懂我写的是什么,那么请下载源码看看,互相学习咯!
源码下载地址:http://download.csdn.net/detail/sdksdk0/9461193
标签:
原文地址:http://blog.csdn.net/sdksdk0/article/details/50887376