如何在片段中显示对话| 安卓

巴克尔·纳克维(Baqer Naqvi)

fragment在我的活动中使用,我想显示一个dialogueOn ItemLongClickListenerof viewlist我尝试了一些代码,但是失败了。反正有做吗?

code

    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
     public boolean onItemLongClick(AdapterView<?> arg0, View v,int index, long arg3) {
                    Toast.makeText(getActivity(),"thul thuk!",Toast.LENGTH_SHORT).show();  
              //show-dialogue here
           return false;
                }
    });
哈里哈兰

试试这个..

custom_dialog.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
<TextView
    android:id="@+id/text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text=""
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="#FFFFFF" />
     </LinearLayout>

爪哇

 listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
 public boolean onItemLongClick(AdapterView<?> arg0, View v,int index, long arg3) {
                Toast.makeText(getActivity(),"thul thuk!",Toast.LENGTH_SHORT).show();  
          Dialog dialog = new Dialog(getActivity());
           dialog.setContentView(R.layout.custom_dialog);
           dialog.setTitle("Custom Dialog");
           dialog.show();  
       return false;
            }
});

编辑

您可以使用上下文菜单

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章