Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - How to save a programmatically created view and restore it on app restart
    primarykey
    data
    text
    <p>I have this nested view created from another activity. The values (texts to show, background color, etc) mainly are inputted by the user from the other activity. Here is the code on how I dynamically create the views:</p> <pre><code>@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { if (requestCode == 1) { // Create a New Linear Layout LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); float scale = getResources().getDisplayMetrics().density; //Set Bottom Margin float margin = 5; //RESIZE BOTTOM MARGIN HERE! int margs = (int) (margin * scale + 0.5f); //Set padding in dp float padding = 5; //RESIZE PADDING HERE! int pads = (int) (padding * scale + 0.5f); llParams.setMargins(0,0,0,margs); //Set Parameters for Android ll.setLayoutParams(llParams); ll.setPadding(pads, pads, pads, pads); //Set Background Color on Layout String chosenColor = data.getStringExtra("sendChosenColor"); if (chosenColor.equals("Green")){ ll.setBackgroundResource(R.color.HoloGreen); }else if (chosenColor.equals("Blue")){ ll.setBackgroundResource(R.color.HoloBlue); }else if (chosenColor.equals("Gray")){ ll.setBackgroundResource(R.color.HoloGray); }else if (chosenColor.equals("Orange")){ ll.setBackgroundResource(R.color.HoloOrange); }else { ll.setBackgroundResource(R.color.HoloYellow); } //Adding Layout to Appropriate Container int layoutCountLeft = subjectLeft.getChildCount(); int layoutCountRight = subjectRight.getChildCount(); if (layoutCountLeft &lt;= layoutCountRight){ subjectLeft.addView(ll); } else { subjectRight.addView(ll); } //Create TextView for SubjectName TextView SubjectName = new TextView(this); SubjectName.setText(data.getStringExtra("sendSubjectName")); SubjectName.setLayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); SubjectName.setTextSize(22); SubjectName.setTypeface(Typeface.DEFAULT_BOLD); //Create TextView for SubjectNumber TextView SubjectNumber = new TextView(this); SubjectNumber.setText(data.getStringExtra("sendSubjectNumb")); SubjectNumber.setLayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); SubjectNumber.setTextSize(16); //Creating the divider line ImageView divider = new ImageView(this); LinearLayout.LayoutParams dividerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 2); divider.setLayoutParams(dividerParams); divider.setBackgroundResource(R.color.Black); //Add Views into the Layout ll.addView(SubjectNumber); ll.addView(SubjectName); ll.addView(divider); } } } </code></pre> <p>Can I save this without using databases?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload