Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <TextView
- android:id="@+id/mEditableText"
- android:layout_width="280dp"
- android:layout_height="0dp"
- android:layout_gravity="center"
- android:layout_marginTop="80dp"
- android:layout_weight="3"
- android:gravity="bottom"
- android:fontFamily="cursive"
- android:text="pressione o n EDITAR ESCOLHAS"
- android:textAlignment="center"
- android:textColor="#000000"
- android:textSize="30dp"
- android:textStyle="bold" />
- <Button
- android:id="@+id/mDecideBTNMain"
- android:layout_width="250dp"
- android:layout_height="0dp"
- android:layout_gravity="center"
- android:layout_marginTop="20dp"
- android:layout_marginBottom="20dp"
- android:layout_weight="1.8"
- android:background="#00008B"
- android:text="decidir"
- android:textColor="#FFFFFF"
- android:textSize="45dp" />
- <Button
- android:id="@+id/mEditChoicesBTNMain"
- android:onClick="GoToEditChoices"
- android:layout_width="250dp"
- android:layout_height="0dp"
- android:layout_gravity="center_horizontal"
- android:layout_marginTop="35dp"
- android:layout_marginBottom="80dp"
- android:layout_weight="2.5"
- android:background="#00008B"
- android:text="Editar escolhas"
- android:textColor="#FFFFFF"
- android:textSize="35dp"
- android:textStyle="bold" />
- </LinearLayout>
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- tools:context=".EditChoices">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:layout_marginTop="60dp"
- android:orientation="horizontal"
- android:layout_weight="1.2">
- <EditText
- android:id="@+id/mAddItemTextEC"
- android:layout_width="0dp"
- android:layout_height="match_parent"
- android:layout_weight="6"
- android:inputType="text"/>
- <Button
- android:id="@+id/mAddItemButtonEC"
- android:layout_width="0dp"
- android:layout_height="match_parent"
- android:layout_weight="4"
- android:background="#00008B"
- android:text="adicionar"
- android:textColor="#FFFFFF"
- android:textSize="25dp"
- />
- </LinearLayout>
- <!--<LinearLayout-->
- <!--android:layout_width="match_parent"-->
- <!--android:layout_height="0dp"-->
- <!--android:layout_marginTop="50dp"-->
- <!--android:layout_weight="4">-->
- <ListView
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:layout_weight="5"
- android:id="@+id/mListViewEC">
- </ListView>
- <!--</LinearLayout>-->
- </LinearLayout>
- public class EditChoices extends AppCompatActivity {
- List <String> AvailableChoices = new ArrayList<String>();
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_edit_choices);
- Button AddItemsButton = (Button) findViewById(R.id.mAddItemButtonEC);
- ListView listview = (ListView) findViewById(R.id.mListViewEC);
- final EditText NameofChoices = (EditText) findViewById(R.id.mAddItemTextEC);
- AddItemsButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if(ValidateText(NameofChoices.getText().toString())){
- AvailableChoices.add(NameofChoices.getText().toString());
- }
- }
- });
- }
- public boolean ValidateText(String text){
- boolean TextValid = false;
- if(!TextEmpty(text)){
- if(!TextDuplicated(text)) {
- TextValid = true;
- }
- }
- return TextValid;
- }
- public boolean TextEmpty(String text){
- boolean TextEmpty = false;
- if((text == "") || (text == " ")){
- TextEmpty = true;
- }
- return TextEmpty;
- }
- public boolean TextDuplicated(String text){
- boolean TextDuplicated = false;
- for(String choice : AvailableChoices){
- if(text == choice){
- TextDuplicated = true;
- }
- }
- return TextDuplicated;
- }
- public class EditChoicesTest {
- EditChoices editchoices = new EditChoices();
- @Test
- public void validateText() {
- boolean b = editchoices.ValidateText(" ");
- assertEquals(b,false);
- }
- @Test
- public void textEmpty() {
- boolean i = !(editchoices.TextEmpty(""));
- assertEquals(i,false);
- }
- @Test
- public void textDuplicated() {
- boolean w = editchoices.TextDuplicated("l");
- boolean q = editchoices.TextDuplicated("l");
- assertEquals(w,false);
- assertEquals(q,false);
- }
- }
Add Comment
Please, Sign In to add comment