Note that there are some explanatory texts on larger screens.

plurals
  1. POAssign edittext ids programmatically and calculate
    text
    copied!<p>Beginner here so sorry for the lack of skill. I'm trying to make an app that dynamically add edittext's and multiply them(rows) and then add the totals in a grand total. I managed to make it dynamically add edittexits,make it scroll,reset but i'm trying to figure out how to assign id's to every textedit and then multiply the values(from the two edit texts on the rows) and then sum all the results in a grand total.I think i know how to set id's for every edittext( with setid(i) with a for) but i can't find a way to I think i found a way but it's a bit hard to try just to possibly fail so i'm asking you guys for help. There has to be an easier way that i don't know,since i'm an absolute beginner. Please give me some alternatives if available and examples of how i can apply them. Thanks in advance !</p> <p>Here's my code so far :</p> <pre><code>@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void produsnou(View v) { LinearLayout l1 = (LinearLayout) findViewById(R.id.layout1); EditText et = new EditText(this); et.setHint("Produs"); l1.addView(et); int count = 4; int i = 4; for (i = 4; i &lt; count; i++) ; LinearLayout l2 = (LinearLayout) findViewById(R.id.layout2); EditText et2 = new EditText(this); et2.setHint("Cantitate"); et2.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); l2.addView(et2); et2.setId(i); LinearLayout l3 = (LinearLayout) findViewById(R.id.layout3); EditText et3 = new EditText(this); et3.setHint("Pret"); et3.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); l3.addView(et3); et3.setId(i + 1); count = count++; RelativeLayout l4 = (RelativeLayout) findViewById(R.id.layout4); } public void reload(View v) { Intent intent = getIntent(); finish(); startActivity(intent); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } </code></pre> <p>}</p>
 

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