xmlif标签里加不加android,android – 如何在解析的XML标签上检查Null值

目前我正在构建这个

Android应用程序,让我难以理解的一件事就是处理ListView项目全部以我需要的顺序显示但是如果一个标签有一个空白值它显示为singleLine对象只占用空间和间距出布局.

此图像ListView项目中的所有空间都是一个正在发送的空字符串,我将其解析.

我想简单地知道处理这个错误的最佳方法吗?

我的ListView项目的XML:

android:layout_width="match_parent"

android:layout_height="match_parent" >

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" />

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" />

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"/>

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" />

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" />

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" />

我需要检查Empty TextViews并隐藏它们.

我的代码在这里:

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> menuItems = new ArrayList>();

Document doc = getDomElement(xml);

if (xml != null) {

{

NodeList nl = doc.getElementsByTagName(KEY_ITEM);

for (int i = 0; i < nl.getLength(); i++) {

HashMap map = new HashMap();

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);

我正在尝试检查值是否为null以将对象添加到HashMap.这当然不起作用,我想知道如何检查那些空TextViews并隐藏它们.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值