• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps getting editText values from for loop

Hi All,

I'm trying to get values from editText and storing in a database. Based on the value given, those number of rows to be added.

using below code:
-----------------

public void addNewQues(View view)
{
EditText editText0 = (EditText) findViewById(R.id.textView0);
int tot_quest_no = Integer.parseInt(editText0.getText().toString());
QDatabaseHandler qdb = new QDatabaseHandler(this);

for (int i = 1; i < tot_quest_no +1; i++)
{
// Setting focus on 1st editText field.

findViewById(R.id.textView1).setFocusableInTouchMode(true);
findViewById(R.id.textView1).requestFocus();

// Getting values for a single row. i.e 5 values from 5 editTexts to 5 fields in a row.

EditText editText = (EditText) findViewById(R.id.textView1);
String quest = editText.getText().toString();
EditText editText1 = (EditText) findViewById(R.id.textView2);
String ans1 = editText1.getText().toString();
EditText editText2 = (EditText) findViewById(R.id.textView3);
String ans2 = editText2.getText().toString();
EditText editText3 = (EditText) findViewById(R.id.textView4);
String ans3 = editText3.getText().toString();
EditText editText4 = (EditText) findViewById(R.id.textView5);
String ans4 = editText4.getText().toString();
EditText editText5 = (EditText) findViewById(R.id.textView6);
String corr_ans = editText5.getText().toString();

// Adding row to database


Log.d("Insert: ", "Inserting ..");
qdb.addQuestion(i, quest, ans1, ans2, ans3, ans4, corr_ans);

// Clearing editText values


editText.setText("");
editText1.setText("");
editText2.setText("");
editText3.setText("");
editText4.setText("");
editText5.setText("");
}


Log.d("EXIT: ", "Exiting ..");
}


By running this code, at a single instance it is storing all the rows and it is not prompting for me to input second row values.


Kindly suggest some idea to get this thing done.
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones