当我点击我的活动的列表视图时,我想显示 alertdialog,我有一个显示 alertdialog 的代码,但我知道我的代码有问题,我不知道如何修复它,警报没有显示我想要,但在 DDMS 中得到我想要的结果。这是我的代码:
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
new bike_type_dao(responsetype).view_bike_type();
final Entity_Brand brand = adapterBrand.getItem(position);
LayoutInflater li = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = li.inflate(R.layout.listview_activity, null, false);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(brand.getBrand_name());
builder.setView(view);
ListView listtype = (ListView) view.findViewById(R.id.list_sepeda);
listtype.setOnClickListener((OnClickListener) this);
listtype.setAdapter(new ArrayAdapter<Entity_Bike_Type>(this,
android.R.layout.simple_list_item_1, arrayList));
listtype.setOnItemClickListener((OnItemClickListener) this);
builder.create().show();
}
谢谢。
那是我的原木猫:
09-18 11:52:07.819: E/HttpResponse(25866): {"result":1,"data":[{"0":"1","id_brand":"1","1":" Polygon","brand_name":"Polygon"},{"0":"2","id_brand":"2","1":"United Bike","brand_name":"United Bike"},{" 0":"3","id_brand":"3","1":"WimCycle","brand_name":"WimCycle"}]} 09-18 11:52:09.669: D/AndroidRuntime(25866): 关闭关闭 VM 09-18 11:52:09.669: W/dalvikvm(25866): threadid=1: 线程退出未捕获异常 (group=0x40018578) 09-18 11:52:09.679: E/AndroidRuntime(25866): FATAL EXCEPTION : 主要 09-18 11:52:09.679: E/AndroidRuntime(25866): java.lang.ClassCastException: com.wilis。hellotabwidget.Tab_Brand_ListView_Activity 09-18 11:52:09.679: E/AndroidRuntime(25866): at com.wilis.hellotabwidget.Tab_Brand_ListView_Activity.onListItemClick(Tab_Brand_ListView_Activity.java:158) 09-18 11:52:09.679: E/AndroidRuntime(25866) ): 在 android.app.ListActivity$2.onItemClick(ListActivity.java:319) 09-18 11:52:09.679: E/AndroidRuntime(25866): 在 android.widget.AdapterView.performItemClick(AdapterView.java:284) 09 -18 11:52:09.679: E/AndroidRuntime(25866): 在 android.widget.ListView.performItemClick(ListView.java:3755) 09-18 11:52:09.679: E/AndroidRuntime(25866): 在 android.widget .AbsListView$PerformClick.run(AbsListView.java:1964) 09-18 11:52:09.679: E/AndroidRuntime(25866): 在 android.os.Handler.handleCallback(Handler.java:587) 09-18 11:52 :09.679: E/AndroidRuntime(25866): 在 android.os.Handler。dispatchMessage(Handler.java:92) 09-18 11:52:09.679: E/AndroidRuntime(25866): at android.os.Looper.loop(Looper.java:130) 09-18 11:52:09.679: E/ AndroidRuntime(25866): 在 android.app.ActivityThread.main(ActivityThread.java:3687) 09-18 11:52:09.679: E/AndroidRuntime(25866): 在 java.lang.reflect.Method.invokeNative(Native Method) 09-18 11:52:09.679: E/AndroidRuntime(25866): 在 java.lang.reflect.Method.invoke(Method.java:507) 09-18 11:52:09.679: E/AndroidRuntime(25866): 在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867) 09-18 11:52:09.679: E/AndroidRuntime(25866): at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:625) 09-18 11:52:09.679: E/AndroidRuntime(25866): at dalvik.system.NativeStart.main(Native Method) 09-18 11:52:09.809: E/HttpResponse(25866): { “结果”:1,"data":[{"0":"1","id_type":"1","1":"Cross Country (XC)","type_name":"Cross Country (XC)"},{"0 ":"2","id_type":"2","1":"BMX","type_name":"BMX"},{"0":"3","id_type":"3","1 ":"搭便车 (FR)","type_name":"搭便车 (FR)"},{"0":"4","id_type":"4","1":"DownHill (DH)" ,"type_name":"DownHill (DH)"},{"0":"5","id_type":"5","1":"DirtJump (DJ)","type_name":"DirtJump (DJ) "},{"0":"6","id_type":"6","1":"公路自行车","type_name":"公路自行车"}]}