ListView中的問題,有點意思

問題:
報修歷史出現了三次,我原本是要它出現一次的,望大神解決之!


XML佈局如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
<LinearLayout 
   android:layout_width="fill_parent"
   android:layout_height="45dp"
   android:id="@+id/ht_title" 
   android:background="@drawable/title_bar"
   android:gravity="center_horizontal|center_vertical"  >  
       <TextView
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="報修歷史"
         android:textSize="20sp"
android:textColor="#ffffff" />       
</LinearLayout>
    <ListView
        android:layout_below="@id/ht_title"
        android:id="@+id/ht_lv_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true">
    </ListView>
    
    <TextView
        android:layout_below="@id/ht_lv_list"
        android:id="@+id/ht_tv_time"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="15sp">        
    </TextView>
    
    <TextView
        android:layout_below="@id/ht_tv_time"
        android:layout_marginTop="5dp"
        android:id="@+id/ht_tv_category"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp">
        
    </TextView>
</RelativeLayout>

java 代碼部分:

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.example.gdin_network_service_system.R;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class History extends Activity{

private ListView lv;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
List<Map<String, String>> datas = new ArrayList<Map<String, String>>();

putData(datas,"time", "2014/12/23傍晚","category","Mac地址綁定錯誤");
putData(datas,"time", "2014/12/22中午","category","用戶名或密碼錯誤");

SimpleAdapter sa = new SimpleAdapter(this, 
datas, 
R.layout.activity_history, 
new String[]{"time","category"},
new int[]{R.id.ht_tv_time,R.id.ht_tv_category});
lv = (ListView) findViewById(R.id.ht_lv_list);
lv.setAdapter(sa);
}
private void putData(List<Map<String, String>> datas,String key1,String value1,String key2,String value2){
Map<String,String> data = new HashMap<String, String>();
data.put(key1,value1);
data.put(key2,value2);
datas.add(data);
}
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章