I spent literally two days trying to figure this out. If anyone could help, I would be very grateful.
What I'm trying to achieve:
Have a ListView, through which the player can add new entries (players), through the text box (for the player’s name), and then the submit button. In each ListView field, I show the name of the player, and then two ImageButtons. One with a male symbol and one with a female symbol. The male symbol is switched by default, and the user can set the player as male or female by switching either the male button or the female button. Finally, as soon as the user moves to the next screen (new action), the application will save the names of the players and the attached floor in some form of storage and move on to the next action.
Achieved:
I have a simple array adapter that when a player adds a new player name to the list, I run notifyDataSetChanged () on it. The adapter is also configured to use a special line layout file. Inside the layout file, it looks like 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>
Two buttons on each line refer to methods in the class file. Here is my code for 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 have not yet implemented any relationship between these two buttons to allow only one to be active at a time or even push one away, as I think I could take the wrong approach completely.
Problem:
, / / , , / , , , , , , ( 0 ) , .
...?
, ,
!
, , , - ; , , , , , , .
, , ? , .
!:)