从接口获取数据展示弹出框列表
程序员文章站
2022-03-11 16:41:25
...
有时候开发的过程中会遇到需要开发人员做一个弹出框列表,数据还是从接口获取出来的,刚开始做小白的时候什么都不懂,就一个小问题都得研究半天,现在记录一下从接口取数据展示弹出框列表的过程:
直接上代码:
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();
}
效果图:
希望能帮助到遇到同样问题的童鞋!
推荐阅读