android - Custom listview with two buttons in each row -



android - Custom listview with two buttons in each row -

i have spent literally 2 days trying sort issue. if help massively appreciative.

what i'm trying achieve:

have listview, whereby player can add together new entries (players), through text field (for player name), , submit button. in each field of listview, display player name, , 2 imagebuttons. 1 male symbol, , 1 female symbol. male symbol toggled default, , user can set player beingness male or female toggling either male button or female button. finally, 1 time user moves onto next screen (a new activity), application save player names , attached sex form of storage , proceed next activity.

what have achieved:

i have simple array adapter, upon player adding new player name list, run notifydatasetchanged() on it. adapter set utilize custom row layout file. within layout file, looks this:

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content"> <relativelayout android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/relativelayout1" android:layout_margintop="5dp"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/playername" android:layout_centervertical="true" android:text="derp" android:textstyle="bold" android:layout_marginleft="5dp" android:textsize="22dp" android:textcolor="@color/male_blue"></textview> <imagebutton android:layout_height="60dp" android:layout_width="60dp" android:onclick="maleclickhandler" android:src="@drawable/male_icon_settings" android:id="@+id/buttona" android:layout_alignparentright="true" android:layout_marginright="65dp"></imagebutton> <imagebutton android:onclick="femaleclickhandler" android:layout_height="60dp" android:layout_width="60dp" android:id="@+id/buttonb" android:layout_alignparentright="true" android:layout_marginright="5dp" android:src="@drawable/female_icon_settings"></imagebutton> </relativelayout> </linearlayout>

the 2 buttons on each row reference methods in class file. here code this:

public void maleclickhandler(view v) { relativelayout vwparentrow = (relativelayout) v.getparent(); imagebutton malebutton = (imagebutton) vwparentrow.getchildat(1); malebutton.setimagedrawable(getresources().getdrawable( r.drawable.male_icon_selected)); vwparentrow.refreshdrawablestate(); } public void femaleclickhandler(view v) { relativelayout vwparentrow = (relativelayout) v.getparent(); imagebutton femalebutton = (imagebutton) vwparentrow.getchildat(2); femalebutton.setimagedrawable(getresources().getdrawable( r.drawable.female_icon_selected)); vwparentrow.refreshdrawablestate(); }

i haven't yet implemented inter-connectivity between these 2 buttons, allow 1 active @ time, or untoggle one, since think might taking wrong approach entirely.

the problem:

upon adding new entries list, after toggling 1 and/or other male/female buttons, things buggy, , male/female toggled icon might move should, along attached player string, or more likely, toggled remain on first row (array position 0 of list), or move sec list position, , re-create beingness toggled onto row above.

how can help...?

i have attached image below of screen, emulator, help illustrate points screenshot!

i think might need utilize form of custom adapter; have done much reading around on subject, can't find relevant trying achieve, if point me in right direction, or seek , set basic solution type of problem, grateful.

finally, when working, form of storage best storing player names, , sex? user able maintain player list after quit application , restarted it.

thanks help! :)

you need utilize custom adapter, in should able track male/female flag each of it's entries.

your method not work since state of buttons managed getview method of adapter. if alter them digging through children, next time when getview method called, it's going mess things.

android listview

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -