android - ArrayAdapter getView method trigger only first element -
i try use listfragment create list.i created custom array adapter listfragment. can see first item on activiy when launch project.but i've noticed when drag , drop fist item can see second item on 1 line.you can see below fragment layout , list item layout.also attached custom adapter class.thanks in advance.
fragment layout
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:baselinealigned="false" android:orientation="horizontal" > <fragment android:id="@+id/menufragment" android:name="com.example.fragment.menulistfragment" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" />
list item layout
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="4dp" > <imageview android:id="@+id/imgmenu" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignparenttop="true" android:src="@drawable/makel_icon" android:contentdescription="@string/desc_mainmenuimages" /> <textview android:id="@+id/txtmenu" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centervertical="true" android:layout_marginleft="20dp" android:layout_torightof="@+id/imgmenu" android:textsize="14sp" android:textstyle="bold" />
my custom array adapter
public class menulistadapter extends arrayadapter<mainmenuinfo> { private list<mainmenuinfo> menulist; private context context; private int layoutresourceid; public menulistadapter(context context, int layoutresourceid, list<mainmenuinfo> menulist) { super(context, layoutresourceid, menulist); this.context = context; this.menulist = menulist; this.layoutresourceid = layoutresourceid; } @override public int getcount() { return menulist.size(); } @override public mainmenuinfo getitem(int position) { return menulist.get(position); } @override public long getitemid(int position) { return menulist.get(position).get_id(); } @override public view getview(int position, view convertview, viewgroup parent) { view view = convertview; if (view == null) { layoutinflater inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service); view = inflater.inflate(layoutresourceid, null); } mainmenuinfo menu = menulist.get(position); imageview imgmenu = (imageview) view.findviewbyid(r.id.imgmenu); if (menu.getimagename() != null) { int r = view.getresources().getidentifier(menu.getimagename(), "drawable", context.getpackagename()); if (r > 0) { imgmenu.setimageresource(r); } } textview txtmenu = (textview) view.findviewbyid(r.id.txtmenu); txtmenu.settext(menu.getmenuname()); return view; }
}
my problem solved.there no error in above code.my fault enter incorrect value in setdividerheight property.therefore listview can not show other items.thanks.
Comments
Post a Comment