從介面獲取資料展示彈出框列表
阿新 • • 發佈:2019-02-07
有時候開發的過程中會遇到需要開發人員做一個彈出框列表,資料還是從介面獲取出來的,剛開始做小白的時候什麼都不懂,就一個小問題都得研究半天,現在記錄一下從介面取資料展示彈出框列表的過程:
直接上程式碼:
private void showlist(){
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
try {
// int memberkey, int solveUserKey, String title, String content, int type,
// String startTime, String endTime, List list
final JSONObject jsobj = BaseDataService.getTyper();
int code = jsobj.getInt("code");
JSONArray results = jsobj.getJSONArray("results");
final List listt = JsonUtils.parseJsonArray(results);
if (code == 100) {
mHandler.post(new Runnable() {
public void run() {
Name = new String[listt.size()];
String name = "";
for (int i = 0; i < listt.size(); i++) {
Map map = (Map) listt.get (i);
int id = new Integer( map.get("worktaskcategorykey").toString());
IdList.add(id);
name += map.get("name").toString() + ",";
}
Name = name.split(",");
new AlertDialog.Builder(AddIncrease.this)
.setTitle("請選擇型別" )
.setItems(Name, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
typeKey = (Integer) IdList.get(which);
Increase_type1.setText(Name[which]);
}
} )
.setNegativeButton("取消" , null )
.show();
}
});
}
if (code!= 100) {
DialogUtils.showPopMsgInHandleThread(AddIncrease.this, mHandler, "提交失敗!");
}
} catch (NetConnectionException e) {
// TODO Auto-generated catch block
DialogUtils.showPopMsgInHandleThread(AddIncrease.this, mHandler, Text.NetConnectFault);
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
DialogUtils.showPopMsgInHandleThread(AddIncrease.this, mHandler, Text.ParseFault);
e.printStackTrace();
}
}
}).start();
}
效果圖:
希望能幫助到遇到同樣問題的童鞋!