Chevy Mark Sunderland

Chevy Mark Sunderland

  • NA
  • 188
  • 166.8k

Android ListViews with Dynamic Data

Apr 11 2014 12:36 PM
I tried loading dynamic data for the ListView in android application.

I don't have error, but the ListView is empty.

If try the same class java with static values the ListView worked.

The input of dynamic data is this string :

Title of article<br />Autor of article
repeated for each item in the database, for example:

Academic writing and publishing<br />Hartley, J.<br /><br />
A practical guidebook<br />Hays, J. C.<br /><br />
JEPS<br />Jamali, H. R.<br /><br />
...
...
Static values

public static final String[] titles = new String[] { "Strawberry",
"Banana", "Orange", "Mixed" };

public static final String[] descriptions = new String[] {
"It is an aggregate accessory fruit",
"It is the largest herbaceous flowering plant", "Citrus Fruit",
"Mixed Fruits" };

public static final Integer[] images = { R.drawable.image1,
R.drawable.image2, R.drawable.image3, R.drawable.image4 };
Dynamic values

try {

httpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();

String myString = response.toString();
String myStringnew = myString.replaceAll("<br />", "\n");
String[] myStrings = myStringnew.split("\n");

final String[] titles = new String[] { myStrings[0].toString() };
final String[] descriptions = new String[] { myStrings[1].toString() };
final Integer[] images = { R.drawable.image1, R.drawable.image2,
R.drawable.image3, R.drawable.image4 };

rowItems = new ArrayList<RowItem>();
for (int i = 0; i < titles.length; i++) {
RowItem item = new RowItem(images[i], titles[i],
descriptions[i]);
rowItems.add(item);
}

listView = (ListView) findViewById(R.id.list);
CustomListViewAdapter adapter = new CustomListViewAdapter(this,
R.layout.list_item, rowItems);
listView.setAdapter(adapter);
listView.setOnItemClickListener(this);

} catch (Exception exception) {

}