Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Check Null on parsed XML tags Value
    text
    copied!<p>Currently i am building this android application and the one thing that has me stumped is the handle <code>ListView</code> items all showing in the order i need them but if one tag has a blank value it shows up as a singleLine object taking up nothing but space and spacing out the layout.</p> <p><img src="https://i.stack.imgur.com/W7yyA.png" alt="Error"></p> <p>All the space in this images ListView items is a Null string being sent and i parse it. I would Simply Like to know the best way to handle this Error?</p> <p>My XML for the ListView Items:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" &gt; &lt;TextView android:id="@+id/ContactTitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="@color/White" /&gt; &lt;TextView android:id="@+id/Name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignRight="@+id/ContactTitle" android:layout_below="@+id/ContactTitle" android:layout_marginRight="17dp" android:textColor="@color/White" /&gt; &lt;TextView android:id="@+id/MainPhone" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignRight="@+id/Name" android:layout_below="@+id/Name" android:textColor="@color/White"/&gt; &lt;TextView android:id="@+id/Cell" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignRight="@+id/MainPhone" android:layout_below="@+id/MainPhone" android:textColor="@color/White" /&gt; &lt;TextView android:id="@+id/Fax" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/Cell" android:layout_below="@+id/Cell" android:textColor="@color/White" /&gt; &lt;TextView android:id="@+id/Email" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/Fax" android:layout_below="@+id/Fax" android:ellipsize="marquee" android:textColor="@color/EmailColor" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>I need to check for the Empty <code>TextViews</code> and hide them. My code is here:</p> <pre><code>protected void onPostExecute(String result) { String xml = result; String KEY_ITEM = "Contact"; String KEY_CONTACTTITLE = "ContactTitle"; String KEY_NAME = "Name"; String KEY_MAINPHONE = "Phone"; String KEY_CELLPHONE = "Cell"; String KEY_FAX = "Fax"; String KEY_EMAIL = "Email"; ArrayList&lt;HashMap&lt;String, String&gt;&gt; menuItems = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); Document doc = getDomElement(xml); if (xml != null) { { NodeList nl = doc.getElementsByTagName(KEY_ITEM); for (int i = 0; i &lt; nl.getLength(); i++) { HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); Element e = (Element) nl.item(i); if (getValue(e, KEY_CONTACTTITLE) != null) { map.put(KEY_CONTACTTITLE, getValue(e, KEY_CONTACTTITLE)); } else { TextView contactTitle = (TextView) findViewById(R.id.ContactTitle); } if (getValue(e, KEY_NAME) != null) { map.put(KEY_NAME, getValue(e, KEY_NAME)); } if (getValue(e, KEY_MAINPHONE) != null) { map.put(KEY_MAINPHONE, getValue(e, KEY_MAINPHONE)); } if (getValue(e, KEY_CELLPHONE) != null) { map.put(KEY_CELLPHONE, getValue(e, KEY_CELLPHONE)); } if (getValue(e, KEY_FAX) != null) { map.put(KEY_FAX, getValue(e, KEY_FAX)); } if (getValue(e, KEY_EMAIL) != null) { map.put(KEY_EMAIL, getValue(e, KEY_EMAIL)); } menuItems.add(map); menuItems = simple; } String[] hashMapObjects = { KEY_CONTACTTITLE, KEY_NAME, KEY_MAINPHONE, KEY_CELLPHONE, KEY_FAX, KEY_EMAIL }; int[] listItemObjects = { R.id.ContactTitle, R.id.Name, R.id.MainPhone, R.id.Cell, R.id.Fax, R.id.Email }; ListAdapter adapter = new SimpleAdapter( MoveContactsActivity.this, menuItems, R.layout.listed_contacts, hashMapObjects, listItemObjects); setListAdapter(adapter); </code></pre> <p>I'm trying to check if the value is null to add the object to the <code>HashMap</code>. This of course doesn't work and I'm wondering how to check for those <code>null</code> <code>TextViews</code> and Hide them.</p>
 

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