0

アクティビティのリストビューをクリックしたときにアラート ダイアログを表示したいのですが、アラート ダイアログを表示するコードはありますが、コードに何か問題があることがわかっており、それを修正する方法がわかりません。アラートは希望どおりに表示されませんでした。 . ここに私のコードがあります:

@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);


    builder = new Dialog(this);
    builder.setTitle(brand.getBrand_name());
    LayoutInflater li = (LayoutInflater) this
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = li.inflate(R.layout.tab_brand_activity, null, false);
    builder.setContentView(view);
    builder.setCancelable(true);

    listtype = (ListView) builder.findViewById(R.id.list_sepeda);
    listtype.setOnItemClickListener((OnItemClickListener) this);
    listtype.setAdapter(new ArrayAdapter<Entity_Bike_Type>(this,
            android.R.layout.simple_list_item_1, arrayList));
    listtype.showContextMenu();


    builder.show();

}

誰かがこの問題で私を助けてくれることを願っています。ありがとうございました。

4

2 に答える 2

2

私はあなたの活動が拡張していると推測していますListActivity(そうでなければ、onListItemClickそもそもオーバーライドするメソッドがありません。

APIドキュメントによると、listView内のアイテムがクリックされると、onListItemClickが呼び出されます。この時点で、アクティビティもとして設定しています。つまり、このアクティビティのどこかでOnItemClickListenerメソッドを定義しているということです。OnItemClick同じことをするので、そのコードを取り出して入れることができますonListItemClick

alertDialogあなたが見せたいものに関しては、私は通常、単純なalertDialogsを作成して表示するために使用することに固執しますAlertDialog.Builder。それは機能し、Dialogクラスを直接操作するよりもおそらく簡単です。

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(brand.getBrand_name());
builder.setCancelable(true);
builder.show();

これがあなたのために働くことを願っています。

于 2012-09-17T03:16:50.670 に答える
0

hmmm let me clarify something, do you want to show a alert dialog when you click the whole list view not the items in it?.. if so, i think you should implement the onclick listener not the onitemclick listenerm though i never tried implementing alert dialog on click of a listview but i think this should do it

于 2012-09-17T02:16:44.210 に答える