I am trying to get to the point where I have a Input (EditText) box in my Activity where users can input ther names. I need it so each time a name is inputed and the button "Add" is clicked it will save that name into a Array So that I can display them on the screen next to the Input (EditText) but also the user needs the ability to remove the last name they just added to the Array with a button that will appear next to the name once it has been added (so kind of needs to save them maybe?).
Also I need to be able to carry over the Array to the next Activity would I have to make it a global Array?
This is what I have so Far:
public class AddRemove extends Activity {
ArrayList<String> playerList = new ArrayList<String>();
String playerlist[];
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.addremove);
Button confirm = (Button) findViewById(R.id.confirm);
confirm.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
final EditText playername = (EditText) findViewById(R.id.userinput);
String name = playername.getText().toString();
playerList.add(name);
}});
}
}
And the XML:
<EditText
android:id="@+id/userinput"
android:layout_width="190dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="22dp"
android:layout_marginTop="95dp"
android:hint="Enter Name"
>
<requestFocus />
</EditText>
<Button
android:id="@+id/confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/userinput"
android:layout_centerVertical="true"
android:text="Add" />