我XML
从Restfull
服务请求中获取,需要将其显示在listView
.
我决定模拟我在在线博客上找到的类似功能,它似乎反馈了原始视图,而不是我分配给元素的视图格式。
现在你可以看到它的重复两次.....在我的移动联系人栏是ListView
开始然后重复的地方之后。
ListView 的 XML:
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/button6"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true" >
</ListView>
以及我用于适配器的 XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left|center"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:paddingLeft="5dp" >
<TextView
android:id="@+id/ContactTitle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"/>
<TextView
android:id="@+id/Name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />
<TextView
android:id="@+id/MainPhone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />
<TextView
android:id="@+id/CellPhone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />
<TextView
android:id="@+id/Fax"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />
<TextView
android:id="@+id/Email"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />
</LinearLayout>
我还不太擅长构建这些ListViews
,并且知道它是我所做的,但我不能把我的手指放在它上面。这是我用于处理数据的Java listView
:
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<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();
Document doc = getDomElement(xml);
if (xml != null) {
{
NodeList nl = doc.getElementsByTagName(KEY_ITEM);
for (int i = 0; i < nl.getLength(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
map.put(KEY_CONTACTTITLE, getValue(e, KEY_CONTACTTITLE));
map.put(KEY_NAME, getValue(e, KEY_NAME));
map.put(KEY_MAINPHONE, getValue(e, KEY_MAINPHONE));
map.put(KEY_CELLPHONE, getValue(e, KEY_CELLPHONE));
map.put(KEY_FAX, getValue(e, KEY_FAX));
map.put(KEY_EMAIL, getValue(e, KEY_EMAIL));
menuItems.add(map);
}
ListAdapter adapter = new SimpleAdapter(MoveContactsActivity.this, menuItems,
R.layout.activity_move_contacts, new String[] {
KEY_CONTACTTITLE, KEY_NAME, KEY_MAINPHONE, KEY_CELLPHONE, KEY_FAX, KEY_EMAIL },
new int[] { R.id.ContactTitle, R.id.Name,
R.id.MainPhone, R.id.CellPhone, R.id.Fax, R.id.Email });
setListAdapter(adapter);
}
}
}
如果有人可以帮助我解决这个问题或让我指出正确的方向,我会很高兴。再次感谢您的时间!