Reputation: 624
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.
Upvotes: 1
Views: 1024
Reputation: 3513
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..
Upvotes: 1