1

i have a xml parser with lazy adapter, i parse all the data to an list view.

now i would like to grabe all the data from the listivew(wiche is 1 textview per row) and put is in and string array but i have no idea how i have to do that. because if i Google i only get results on how to use and string array to populate the list.

my parser:

TextView txt =(TextView)vi.findViewById(R.id.tv);
HashMap<String, String> song = new HashMap<String, String>();
song = data.get(position);     
txt.setText(song.get(MainActivity.KEY_TXT));

the method i use (so far) for getting my string array:

private String[] txt = {

}

thanks in advance.

1
  • I may misunderstand your question but can't you simple make a method in the ListView's adapter to get the data and put it in a string array? I hope you're not searching for the TextView's from the ListView' rows with that code. Commented Oct 25, 2012 at 10:32

1 Answer 1

1

You just have to use the string array in getView() method of listView adapter. like this:--

give the size of strArray same as the size of listView.

String strArray[] = new String[<size of Your ListView>]; 

@Override
public View getView(int position, View convertView, ViewGroup parent) {


    TextView textView;
    if (convertView == null) {

        convertView = inflater.inflate(R.layout.listitem, parent, false);
        textView = (TextView) convertView
                .findViewById(R.id.textView);
    }
    strArray[position] = textView.getText().toString();
    return convertView;
}

now u want to use this strArray to other class then either you have to make it static or you could pass this to other class via intent.like this:--

Bundle b=new Bundle();
b.putStringArray(key, new String[]{value1, value2});
Intent i=new Intent(context, Class);
i.putExtras(b);

and then in other activity class You should get this String array by putting this code:--

Bundle b=this.getIntent().getExtras();
String[] array=b.getStringArray(key);

and if the class to whom you want to pass the String Array( that is strArray) is not Activity then You should make your strArray static like this:

public static strArray[];

now i think your problem will be solved..

Sign up to request clarification or add additional context in comments.

4 Comments

i get an error on the strArray, what am i supposed to fill in there?
sorry i dont understand u ... please explain
i need to use the string array whit all the txt in an other class and i don't know how to do that, can you help?
it will run for sure because i had tried it out... You just give the size of strArray same as listview's size.. ok

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.