In my app, I need to capture multiple data from user when they signup. To avoid multiple EditText from being packed into one layout I have decided to use multiple layouts from within one activity. One layout will capture emails, another phone numbers and so on. When I enter data into an EditText in one layout, a button takes me to the next. What I have done (As a test) is this:
SignupActivity
public class SignupActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
final List<String> myData = new ArrayList<>();
final EditText displayNameEditText = (EditText) findViewById(R.id.displayNameEditText);
Button mainNextButton = (Button) findViewById(R.id.nextButtonMain);
mainNextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
myData.add(displayNameEditText.getText().toString());
setContentView(R.layout.phone_numbers_capture);
final EditText phone1EditText = (EditText) findViewById(R.id.phone1EditText);
Button phoneNextButton = (Button) findViewById(R.id.phoneNumbersUINextButton);
phoneNextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
myData.add(phone1EditText.getText().toString());
Log.e("TAG IT", "Full name : " + myData.get(0));
Log.e("TAG IT", "Phone 1 : " + myData.get(1));
}
});
}
});
}
}
The output I get is this (LogCat)
I can then pass this info from myData
like this when I get to the last layout:
MyObject myObject = new MyObject();
myObject.setFullName(myData.get(0)) //Method expects a String, no issues
myObject.setPhoneNumberOne(myData.get(1)) //Method expects a string, no issues
Now I feel this isn't the best way to do this. First of all, What If I want to capture different data types from each layout?
List<Object> myData
comes to mind, and then what? What other approach can I use to achieve this? If I leave it as is, what problems can I encounter in the future, besides the obvious datatype one I mentioned?