Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Looping through an array of edittexts and getting the texts of each

Emmanuel OkochaEmmanuel Okocha Member Posts: 1

I have an autogenerated list of edittexts gotten from the user input. What i want to do is shuffle the edittexts when the shuffle button is clicked or get the texts and set them to different edittexts. What i tried doing is to get the texts of each edittext adding it to an arraylist and shuffling it and then recreating the layout with the shuffled list. But that in itself is giving me errors. Can someone please help me with a solution. Thank you.

`@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

btnForCreate = (Button)findViewById(R.id.btnCreateTxt);
editTextForInputToCreate = (EditText)findViewById(R.id.textForInputToCreate);

// listViewToDisplayEditTexts = (ListView)findViewById(R.id.listViewForEditTexts);
listLayout = (LinearLayout) findViewById(R.id.listLayout);
btnDisplay = (Button)findViewById(R.id.btnDisplay);
btnShuffleTxt = (Button)findViewById(R.id.btnShuffleTxt);

editTextForInputToCreate.animate().translationX(-1000f);

// listViewToDisplayEditTexts.animate().translationX(-1500f);

btnForCreate.setOnClickListener(new View.OnClickListener() {
    <a href="/profile/Override">@Override</a>
    public void onClick(View view) {

        bringTextInputBackOnScreen();


    }
});





btnDisplay.setOnClickListener(new View.OnClickListener() {
    <a href="/profile/Override">@Override</a>
    public void onClick(View view) {

// length = Integer.parseInt(editTextForInputToCreate.getText().toString());
//
//
// list = new ArrayList();
//
// arrayAdapter = new CustomAdapterForCreateButton(getApplicationContext(), list);
//
// listViewToDisplayEditTexts.setAdapter(arrayAdapter);

        if (editTextForInputToCreate.getText().toString().length()>= 0)
        {
            try {
                listLayout.removeAllViews();

            }catch (Throwable throwable)
            {
                throwable.printStackTrace();
            }
        }

length = Integer.parseInt(editTextForInputToCreate.getText().toString());

        for ( i =0; i<length; i++)
        {
            editTextCollection = new EditText[length];
            editText = new EditText(MainActivity.this);
            editText.setId(i+1);
            editText.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT));
            editText.setHint("Input" + " " + (i+1));
            listLayout.addView(editText);
            editTextCollection[i]=editText;



        }


    }



});




btnShuffleTxt.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {

        listLayout.removeAllViews();
        System.out.println(editText);

// for (EditText gottenEditText:editTextCollection)
// {
// String gottenTexts = gottenEditText.getText().toString();
// list.add(gottenTexts);
// }
//
// Collections.shuffle(list);

// TransitionManager.beginDelayedTransition(listLayout, new ChangeBounds());
// Collections.shuffle(list);
// createViews( inflater, listLayout, list);

    }




});

private void bringTextInputBackOnScreen()
{
editTextForInputToCreate.animate().translationXBy(1000f).setDuration(2000);
}`

Tagged:
Sign In or Register to comment.