实在不好意思~ 什么东西都要问。
大概就是执行到红色字体部分失败报错 然后跳出Sorry对话框 程序重新启动
button_courseAttendace.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
SharedPreferences sharedata=getSharedPreferences("data", 0);
tid = Integer.parseInt(sharedata.getString("userID",null));
P.p(" tid "+tid);
RequestParams params = new RequestParams();
params.put("tid", tid+"");
params.put("action", "search_teacherCourse");
client.post(HttpUtil.server_teacher_course, params,
new JsonHttpResponseHandler() {
@Override
public void onSuccess(int arg0, JSONObject arg1) {
JSONArray object = arg1.optJSONArray("result");
P.p(object.toString()+1111);
if(object.length()==0){
Toast.makeText(WelcomeActivity.this,"您还没教授任何课程!", Toast.LENGTH_SHORT).show();
}else{
for(int i=0;i<arg1.optJSONArray("result").length();i++){
JSONObject object_temp = arg1.optJSONArray("result").optJSONObject(i);
P.p(object_temp.toString()+2222);
list.add(i, (object_temp.optInt("CId")+" "+(object_temp.optString("CName"))));
}
LinearLayout.LayoutParams lp=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
ListView lv = new ListView(WelcomeActivity.this);
ArrayAdapter<String> a = new ArrayAdapter<String>(WelcomeActivity.this,
R.layout.listview_item_1, list);
lv.setAdapter(a);
LinearLayout listViewLayout = new LinearLayout(WelcomeActivity.this);
listViewLayout.setOrientation(LinearLayout.VERTICAL);
listViewLayout.addView(lv,lp);
final AlertDialog dialog = new AlertDialog.Builder(WelcomeActivity.this)
.setTitle("选择课程").setView(listViewLayout)//在这里把写好的这个listview的布局加载dialog中
.create();
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0,View arg1,int arg2,long arg3){
courseInfo = list.get(arg2);
dialog.dismiss();
}
});
dialog.show();
}
super.onSuccess(arg0, arg1);
}
});
}
});
------解决方案--------------------
设置一个layout_height