編輯:關於Android編程
一、數據操作中涉及到的數據接口
發送請求的對象
AndroidFxBLClientAPI FxBL = new AndroidFxBLClientAPI(url);
其中url=”服務器地址”+數據接口。
處理返回請求的對象
FxBLResponse response = new FxBLResponse(res);
在相應數據庫中新建一張表(如下圖)
測試數據
二、安卓GUI界面操作
2.1 把數據查詢到TextBox等控件內
(1)查詢界面
(2)查詢時用的存儲過程
[sql]
ALTER proc [dbo].[ACT_TEST_GET_KHXX]
(
@KHBH nvarchar(100),
@return_msg nvarchar(100)output,
@return_value int output
)
as begin
select * from T_AD_TEST where KHBH=@KHBH
set @return_msg=''
set @return_value=1
end
(3)UI查詢事件掛接
[java]
findViewById(R.id.btnOK).setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//查詢用的地址
String url ="http://169.254.1.30:8088/";
url=url+"GetDbStore.ashx?act=ACT_TEST_GET_KHXX¶ms=1&formId=F0102"
//綁定到請求中的Handler對象,
Handler handler = new Handler() {
public void handleMessage(Message message) {
switch (message.what) {
case HttpConnection.DID_START: {
break;
}
case HttpConnection.DID_SUCCEED: {
doFxBLCallBack((String) message.obj);
break;
}
case HttpConnection.DID_ERROR: {
break;
}
}
}
};
//發送請求的對象
AndroidFxBLClientAPI FxBL = new AndroidFxBLClientAPI(url);
//添加與存儲過程中對應的參數
FxBL.AddParam("KHBH", txtBH.getText().toString());
//綁定Handler對象
FxBL.BindHandler(handler);
//發送請求
FxBL.Request();
}
//連接成後的處理方法
private void doFxBLCallBack(String res) {
//處理返回請求的對象
FxBLResponse response = new FxBLResponse(res);
//存放返回的數據
ArrayList<HashMap<String,String>> list=response.GetArrayList();
if (list != null) {
//賦值
txtKHXM.setText(list.get(0).get("KHMC"));
txtZJLX.setText(list.get(0).get("ZJLX"));
txtZJH.setText(list.get(0).get("ZJH"));
txtLXDH.setText(list.get(0).get("LXDH"));
}
}
});
2.2 把數據查詢到ListView中
(1)查詢界面
(2)查詢用的存儲過程
[sql]
create proc [dbo].[ACT_AD__KHXX]
(
@KHBH nvarchar(100),
@limit int,
@start int,
@totalcount int output
)
as begin
select @totalcount=count(*) from T_AD_TEST where KHBH like '%'+@KHBH
select * from T_AD_TEST where KHBH like '%'+@KHBH
end
(3)UI事件掛接
[java]
findViewById(R.id.btnJS).setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
String url ="http://169.254.1.30:8088/";
url=url+"GetDbStoreByPage.ashx?act=ACT_AD__KHXX¶ms=3&formId=F0201"
Handler handler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case HttpConnection.DID_START: {
break;
}
case HttpConnection.DID_SUCCEED: {
Log.i("DID_SUCCEED", ""
+ HttpConnection.DID_SUCCEED);
doFxBLCallBack((String) msg.obj);
break;
}
case HttpConnection.DID_ERROR: {
Log.i("tetst", "test");
break;
}
}
super.handleMessage(msg);
}
};
AndroidFxBLClientAPI FxBL = new AndroidFxBLClientAPI(url);
FxBL.AddParam("KHBH", txtBH.getText().toString());
FxBL.AddParam("start", "0");
FxBL.AddParam("limit", "20");
FxBL.BindHandler(handler);
FxBL.Request();
}
private void doFxBLCallBack(String res) {
Log.i("click", "click");
FxBLResponse response = new FxBLResponse(res);
Log.i("GetSuccess", response.GetReturn_msg());
ArrayList<HashMap<String,String>> arrayList=response.GetArrayList();
SimpleAdapter adapter=new SimpleAdapter(FxBIActivity.this, arrayList,
R.layout.listview,new String[]{"KHMC","LXDH"},
new int[]{R.id.txt_list_KHMC,R.id.txt_list_lxdh});
listView.setAdapter(adapter);
// txt.setText(list.get(9).getValue());
// txt.setText(response.GetRowString(1));
}
});
2.3 數據寫入
(1)數據寫入界面
(2)相關數據表
(3)數據寫入存儲過程
[sql]
alter proc ACT_AD_HTXX_ADD
(
@KHBH nvarchar(100),
@KHMC nvarchar(100),
@ZJLX nvarchar(100),
@ZJH nvarchar(100),
@LXDH nvarchar(100),
@return_msg nvarchar(100) output,
@return_value int output,
@result nvarchar(100) output
)
as begin
insert T_AD_TEST(KHBH,KHMC,ZJLX,ZJH,LXDH) values(@KHBH,@KHMC,@ZJLX,@ZJH,@LXDH)
set @return_msg=''
set @return_value=1
set @result=''
end
(4)UI事件掛接
[java]
findViewById(R.id.btnADD).setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
String url = "http://169.254.1.30:8088/Execute.ashx?act=ACT_AD_HTXX_ADD¶ms=7&formId=F0201";
Handler handler = new Handler() {
public void handleMessage(Message message) {
switch (message.what) {
case HttpConnection.DID_START: {
break;
}
// 連接成功後的處理
case HttpConnection.DID_SUCCEED: {
Log.i("DID_SUCCEED", ""
+ HttpConnection.DID_SUCCEED);
doFxBLCallBack((String) message.obj);
break;
}
case HttpConnection.DID_ERROR: {
break;
}
}
}
};
AndroidFxBLClientAPI FxBL = new AndroidFxBLClientAPI(url);
Log.i("KHBH", "" + txtBH.getText().toString());
//這個兩個參數是必須的,而且必須在其他參數前添加
FxBL.AddParam("sys_username", "admin");
FxBL.AddParam("sys_password", "123456");
==============
FxBL.AddParam("KHBH", txtBH.getText().toString());
FxBL.AddParam("KHMC", txtKHXM.getText().toString());
FxBL.AddParam("ZJLX", txtZJLX.getText().toString());
FxBL.AddParam("ZJH", txtZJH.getText().toString());
FxBL.AddParam("LXDH", txtLXDH.getText().toString());
FxBL.BindHandler(handler);
FxBL.Request();
}
private void doFxBLCallBack(String res) {
Log.i("click", "click");
FxBLResponse response = new FxBLResponse(res);
Log.i("GetSuccess", response.GetReturn_msg());
}
});
2.4 小結
數據刪除、修改和添加的操作類似。
三、總結
通過JCFXBL平台API,Android下的應用程序可以很方便的訪問JCFXBL平台的數據庫(如MS SQL、Oracle、MySQL等等)
作者:ex_net
很多朋友在啟動應用或者玩游戲的時候都出現Google Play服務已停止運行,或者之前運行正常的應用突然不能使用了。這是為什麼?在這我們就來講解一下Goog
一、概述最新github上開源了很多熱補丁動態修復框架,大致有:上述三個框架呢,根據其描述,原理都來自:安卓App熱補丁動態修復技術介紹,以及Android
解決方法:找到項目最外層的build.gradle文件,將其中的:dependencies {classpath 'com.android.tools.build
本文實例實現一下 RecyclerView,代碼比較簡單,適合初學者,如有錯誤,歡迎指出。復習 ListView可以查看這篇文章深入淺出學習Android ListVie