Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Updating ListView
    primarykey
    data
    text
    <p>I have looked at <a href="https://stackoverflow.com/questions/3588893/android-how-to-update-listview-item-that-is-currently-displayed">Android - how to update ListView item that is currently displayed</a> and <a href="http://commonsware.com/Android/excerpt.pdf" rel="nofollow noreferrer">http://commonsware.com/Android/excerpt.pdf</a> and the Android documentation but I still don't understand.</p> <p>My problem:<br> Using a handler, I am trying to update a Stock data multi-column listview which I have populated from a webservice which retrieves data from a MySQL database. To update the listview, I am calling a servlet which returns an XML that I loop through using DOM. </p> <p>I cannot find a working way to apply the new data (from the XML) into the Listview, though only the third column (Trade Column) has to be updated. Also when I try to cast a View from a ListView row, I get a NullPointerException and can't figure out why. </p> <p>The code I have done so far is below.</p> <p><strong>java Code:</strong></p> <pre><code>private void updateUI() throws Exception { Date dt = new Date(); int hours = dt.getHours(); int minutes = dt.getMinutes(); int seconds = dt.getSeconds(); String curTime = hours + ":" + minutes + ":"+ seconds; refreshHandler.sleep(60000); ListView listview = (ListView) findViewById(R.id.listview); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse("http://10.0.0.29:8080/CI3500/FTSEXML"); //Filter and store ALL 'update' XML elements into node array NodeList nodeList = doc.getElementsByTagName("update"); View v = null; TextView t = null; Adapter adapter = listview.getAdapter(); for (int i = 0; i &lt; adapter.getCount(); i++) { v = listview.getChildAt(i); t = (TextView)v.findViewById(R.id.item2); String companyCode = t.getText().toString(); //Column 1 for(int j = 0; j &lt; nodeList.getLength(); j++) { if(companyCode == nodeList.item(j).getFirstChild().getNodeValue()) { //TODO Update Listview Code } } } txtStatus.setText(String.valueOf("Last Update: " + curTime)); } </code></pre> <p>The listview mapping is as follows:</p> <pre><code>// create the grid item mapping String[] columns = new String[] {"col_1", "col_2", "col_3" }; int[] rows = new int[] { R.id.CodeColumn, R.id.NameColumn, R.id.TradeColumn }; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload