android - GridView.setOnItemClickListener is not triggering -
i trying add feature where, whenever user clicks on edittext start typing in last empty gridview item, new empty gridview item added. problem listener doesn't called when user starts typing. know there questions here similar issues, gridview has edittext in think problem is.
here listener have:
rolelayout.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { system.out.println(rolearraylist.get(position).getrole() + "******"); if(rolearraylist.get(position).getrole().equals("")) { if (rolearraylist.size() == 1 ) { rolearraylist.add(new newroleelement()); } else { if (!rolearraylist.get(rolearraylist.size() - 1).getrole().equals("")) { rolearraylist.add(new newroleelement()); } } } } });
and here xml code gridview
:
<gridview android:id="@+id/rolelist" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:numcolumns="1" android:stretchmode="columnwidth" />
here xml code actual item:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="48dp" android:layout_rowweight="1" android:background="@drawable/my_layout_bg" android:orientation="horizontal"> <edittext android:id="@+id/roletext" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="2" android:ems="10" android:hint="enter new role" android:inputtype="textpersonname" /> <checkbox android:id="@+id/checkbox" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="3" android:text="repeat?" /> </linearlayout>
my adapter code here:
public class roleadapter extends baseadapter{ context c; public roleadapter(context context) { this.c = context; } @override public int getcount() { return rolearraylist.size(); } @override public object getitem(int position) { return rolearraylist.get(position); } @override public long getitemid(int position) { return rolearraylist.indexof(position); } @override public view getview(final int position, view convertview, viewgroup parent) { layoutinflater inflater = (layoutinflater) c.getsystemservice(context.layout_inflater_service); if (convertview == null) { convertview = inflater.inflate(r.layout.role_template, null); } rolearraylist.get(position).setroleinput((edittext) convertview.findviewbyid(r.id.roletext)); rolearraylist.get(position).setrepeatcheckbox((checkbox) convertview.findviewbyid(r.id.checkbox)); return convertview; } }
the main problem edittext
, checkbox
capture focus
try in code.
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="48dp" android:layout_rowweight="1" android:descendantfocusability="blocksdescendants" android:background="@drawable/my_layout_bg" android:orientation="horizontal"> ...... </linearlayout>
add android:descendantfocusability="blocksdescendants"
in root xml code .
another way
also can set android:focusable="false"
in edittext
, set android:clickable="false"
in checkbox
.
Comments
Post a Comment