-2
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_log);
    mLayout = (LinearLayout) findViewById(R.id.linear_layout_logbook);
    max_bpm = (EditText) findViewById(R.id.dL_max_heartrate);
    min_bpm = (EditText) findViewById(R.id.dL_min_bpm);
    avg_speed = (EditText) findViewById(R.id.dL_Average_Speed);
    date = (EditText) findViewById(R.id.dL_date);
}


public void OnClick(View v) {
    max_bpm_in = max_bpm.getText().toString();
    min_bpm_in = min_bpm.getText().toString();
    avg_speed_in = avg_speed.getText().toString();
    date_in = date.getText().toString();
    mLayout.addView(createNewTextView(max_bpm_in,min_bpm_in,avg_speed_in,date_in));


}
private TextView createNewTextView(String max_bpm, String min_bpm, String avg_speed, String date) {
    final ActionBar.LayoutParams lparams = new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT);
    final TextView textView = new TextView(this);
    textView.setLayoutParams(lparams);
    textView.setText("Date: " + date + "\nMaximum Heat Rate: " + max_bpm + "\nMinimum Heart Rate: " + min_bpm + "\nAverage Speed: " + avg_speed);
    return textView;
}

As you can see I wish to take the information from certain edittexts and then create a textview in a new activity using the information inputted into the text views. I want to do this is such a way that new text views can be added with every button click as the information is going to displayed a log.

The application crashes upon the button press which uses Android:onClick in the xml.

Is there something I am missing?

  • 1
    First of all, post your crash log here. Probably a problem is in layout params. You should use LayoutParams from your parent container(in your case LinearLayout). Try to change ActionBar.LayoutParams to LinearLayout.LayoutParams – Yurii Kyrylchuk Mar 25 '18 at 22:07

2 Answers2

0

you can use intent.putExtra(), it requires a key value pair look here as this explains how to use it

Tenzin Choklang
  • 504
  • 1
  • 5
  • 21
0

Any reason against using a RecyclerView (or ListView) and adding the entries from the EditText? If it is an option, you can take a look at this guide for explanation and example:

https://developer.android.com/guide/topics/ui/layout/recyclerview.html

Good luck!

Kaamel
  • 1,852
  • 1
  • 19
  • 25