【Android 个人理解(七)】用ContentValues和自定义Application

我当时面临的需求是 1、核心算法数据和UI的交互,2、多个数组数据的封装,3、不确定的数组数据转化到表格形式。

就于以上需求,我采用自定义的Application储存和传递全局的数据,采用ContentValues的key-value转化和储存数组数据,然后通过遍历ContentValues的key将对应的值填入对应的表格。

大体的步骤如下: 1、从UI界面获取数据,通过循环填充成数组。

// 得到三个初始化编号的值private void SetValuesAtNewTab(View newTab) {edit_node_sum = (EditText) newTab.findViewById(R.id.edit_node_sum);edit_pole_sum = (EditText) newTab.findViewById(R.id.edit_pole_sum);edit_support_sum = (EditText) newTab.findViewById(R.id.edit_support_sum);mysum_node = Integer.parseInt(edit_node_sum.getText().toString());mynm_of_element = Integer.parseInt(edit_pole_sum.getText().toString());mynm_of_support_node = Integer.parseInt(edit_support_sum.getText()= new double[mysum_node];node_F_Disp = new double[2 * mysum_node];node_ID = new int[2 * mynm_of_element];E = new double[mynm_of_element];app.setSum_node(mysum_node);app.setNm_of_element(mynm_of_element);app.setNm_of_support_node(mynm_of_support_node);}private void SetValuesAtPointTab(View tabPoint) {retrain_matrix = new int[3 * mysum_node];et_nodeid = (EditText) tabPoint.findViewById(R.id.et_nodeid);et_x = (EditText) tabPoint.findViewById(R.id.et_x_tabpoint);et_y = (EditText) tabPoint.findViewById(R.id.et_y_tabpoint);et_f_x = (EditText) tabPoint.findViewById(R.id.et_f_x);et_f_y = (EditText) tabPoint.findViewById(R.id.et_f_y);et_retrain_x = (EditText) tabPoint.findViewById(R.id.et_retrain_x);et_retrain_y = (EditText) tabPoint.findViewById(R.id.et_retrain_y);int node = Integer.parseInt(et_nodeid.getText().toString());if (node > 0) {X[node – 1] = Double.parseDouble(et_x.getText().toString());Y[node – 1] = Double.parseDouble(et_y.getText().toString());node_F_Disp[2 * node – 2] = Double.parseDouble(et_f_x.getText().toString());node_F_Disp[2 * node – 1] = Double.parseDouble(et_f_y.getText().toString());retrain_matrix[3 * node – 3] = node;retrain_matrix[3 * node – 2] = Integer.parseInt(et_retrain_x.getText().toString());retrain_matrix[3 * node – 1] = Integer.parseInt(et_retrain_y.getText().toString());} else {Toast.makeText(this, “ID最小为0”, Toast.LENGTH_SHORT).show();}// 传值app.setX(X);app.setY(Y);app.setNode_F_Disp(node_F_Disp);app.setRetrain_matrix(retrain_matrix);app.setBoundDisp_NodeForce(BoundDisp_NodeForce);}private void SetValuesAtBarTab(View tabBar) {et_id_pole = (EditText) tabBar.findViewById(R.id.et_id_pole);et_node_left = (EditText) tabBar.findViewById(R.id.et_node_left);et_node_right = (EditText) tabBar.findViewById(R.id.et_node_right);et_prop = (EditText) tabBar.findViewById(R.id.et_prop);int id_pole = Integer.parseInt(et_id_pole.getText().toString());node_ID[2 * id_pole – 2] = Integer.parseInt(et_node_left.getText().toString());node_ID[2 * id_pole – 1] = Integer.parseInt(et_node_right.getText().toString());E[id_pole – 1] = Double.parseDouble(et_prop.getText().toString());app.setNode_ID(node_ID);app.setE(E);}要做一个积极勇敢乐观的追梦人,永远不说消极的话,

【Android 个人理解(七)】用ContentValues和自定义Application

相关文章:

你感兴趣的文章:

标签云: