samedi 21 novembre 2015

Android App. Create checkbox from a text field

i'm new on java and android programming. What i'm trying to do is to create an app that creates a checkbox after introducing a name in an EditText field. Like creating a todo list or a shopping list.

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

public void storeProduct(View view) {
    //Input name
    EditText productField = (EditText) findViewById(R.id.product_field);
    String product = productField.getText().toString();
}

public void createCheckBox(String product){
    //Create Checkbox
    CheckBox savedPRoduct = new CheckBox(getApplicationContext());
    savedProduct.setText(producto);
}

This is what I got so far. And I'm not sure if it's correct. I've been loocking documentation and some forums including this one and I managed to create the method storeProduct to save the string from the EditText view. Then I create the method createCheckbox that generates the checbox with the string from the EditText view. What I'm not sure is hoy to create the method that displays the checkbox created.

Any clues and info you could share with me is really appreciated.

Thank you very much.




Aucun commentaire:

Enregistrer un commentaire