android - How can I implement Long Click Listener for listview -


this question has answer here:

i searched on various forums right answer nothing works me. moment have code in private class mydiary:

listview list = new listview(monday.this);         list.setonitemlongclicklistener(new adapterview.onitemlongclicklistener() {                 public boolean onitemlongclick(adapterview<?> parent, view view, int position, long id) {                     new editlistitemdialog(view.getcontext()).show();                  return true;                    }         }); 

it doesn't return errors editlistitemdialog not open. missing here?

edit

code editlistitemdialog:

package com.example.classorganizer;  import android.app.dialog; import android.content.context; import android.os.bundle; import android.view.view; import android.widget.button; import android.widget.edittext; import android.widget.textview;  class editlistitemdialog extends dialog implements view.onclicklistener {  private view edittext;  public editlistitemdialog(context context) {     super(context); }  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.edit_text_dialog);//here xml edittext , 'ok' , 'cancel' buttons     view btnok = findviewbyid(r.id.button_ok);     edittext = findviewbyid(r.id.edit_text);     btnok.setonclicklistener(this); }  @override public void onclick(view v) {     ((textview) edittext).gettext().tostring();//here updated(or not updated) text     dismiss(); } } 

xml files:

     <listview         android:layout_width="fill_parent"                         android:gravity="center"         android:layout_height="fill_parent"     android:id="@android:id/list"         android:longclickable="true"          >      </listview> 

and create row:

<?xml version="1.0" encoding="utf-8"?> <relativelayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_alignleft="@+id/name" android:layout_below="@+id/name" xmlns:android="http://schemas.android.com/apk/res/android" android:padding="0dip"> <textview android:textsize="16dip"                                 android:layout_width="wrap_content"                             android:layout_height="29dp"                             android:layout_margintop="0dp"                             android:id="@+id/name"                             android:layout_marginright="4dp"                             android:text="diary title"                             android:textstyle="bold"                             android:longclickable="true" />    </relativelayout> 

assuming using listactivity should change following line (from first code block)...

listview list = new listview(monday.this); 

...to be...

listview list = getlistview(); 

you can set listener it.


Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -