android数据库加载,从在线MySQL数据库加载数据到Android应用程序

我正在使用此代码从在线数据库加载数据到我的android应用程序。 我想知道我可以添加什么来使此代码更好? 有时进度对话框不停地旋转,永远不会获取数据,应用程序被卡住了,关于如何防止这种情况的任何想法?从在线MySQL数据库加载数据到Android应用程序

class LoadAllSections extends AsyncTask

{

// make a progress dialog appear with the selected specifics

@Override

protected void onPreExecute() {

super.onPreExecute();

pDialog = new ProgressDialog(MainActivity.this);

pDialog.setMessage("Loading all sections, please wait");

pDialog.setIndeterminate(false);

pDialog.setCancelable(false);

pDialog.show();

}

// in the background run this code to retrieve data from the server

protected String doInBackground(String... args)

{

List params = new ArrayList();

JSONObject json = jParser.makeHttpRequest(url_Sections,"POST", params);

try

{

int success = json.getInt(TAG_SUCCESS);

sections = json.getJSONArray(TAG_SECTIONS);

if (success == 1)

{

for (int i = 0; i < sections.length(); i++)

{

JSONObject c = sections.getJSONObject(i);

section_id = c.getString(TAG_SECTION_ID);

section_name = c.getString(TAG_SECTION_NAME);

section_desc = c.getString(TAG_SECTION_DESC);

section_image = c.getString(TAG_SECTION_IMAGE);

section_valid = c.getString(TAG_SECTION_VALID);

HashMap sectionmap = new HashMap();

sectionmap.put(TAG_SECTION_ID, section_id);

sectionmap.put(TAG_SECTION_NAME, section_name);

sectionmap.put(TAG_SECTION_DESC, section_desc);

sectionmap.put(TAG_SECTION_IMAGE, section_image);

sectionmap.put(TAG_SECTION_VALID, section_valid);

sectionlist.add(sectionmap);

}

}

else

{

finish();

}

}

catch (JSONException e)

{

e.printStackTrace();

}

return null;

}

// disable the progress dialog and load data to the gridview

protected void onPostExecute(String file_url)

{

pDialog.dismiss();

adapter=new SectionAdapter(MainActivity.this,sectionlist);

SectionsGridView.setAdapter(adapter);

}

}

2014-04-17

Jasser

+0

这段代码没有办法工作......你在问“从在线MySQL数据库加载数据到android应用程序”并发送一个“POST”?我会看看这应该如何工作? –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值