0

I have a Activity that pulls an Array from the previous Activity. I can use this code below which gets the Array from the previous Activity and puts it into a TextView.

Update using initWheel(R.id.passw_1, names.toArray(new String[names.size()])); fixed the problem

ArrayList<String> names = intent.getStringArrayListExtra("KEY");

    TextView et2 = (TextView) findViewById(R.id.editText2);
    et2.setText("");
    if (names.size() > 0) {
        for (String str : names) {
            et2.append(str + "    ");
        }
    }

This works fine but is not what I need exactly. Instead of it populating a TextView I need it to fill a String which is like this

initWheel(R.id.passw_1, "ArrayList Here");

I have another which will be set by default in the code that looks like this and I need the array to populate the one above in the same format:

initWheel(R.id.passw_2, new String[] { "Foo", "Bar" });

2
  • What exactly does "initWheel" do? Commented Jan 13, 2012 at 11:27
  • Well it is a wheel that can be spun around so for R.id.passw_2 it fills the wheel with values "foo" and "bar" Commented Jan 13, 2012 at 11:30

1 Answer 1

3

I think you are asking about getting string array from arraylist, if so please use following method:

String[] strArr = list.toArray();
Sign up to request clarification or add additional context in comments.

6 Comments

I dont quite understand how to implement that?
Assuming the ArrayList is named names you could do initWheel(R.id.passw_2, names.toArray(new String[names.size()]));
@Jens that makes more sense would that output it exactly like initWheel(R.id.passw_2, new String[] { "Foo", "Bar" });
Yes, the return value of the names.toArray(new String[names.size()]) call is a String[], i.e. exactly what you are passing when you pass new String[]{"foo","bar"}.
@Jens Cool Ill give it a test now :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.