问题:
报修历史出现了三次,我原本是要它出现一次的,望大神解决之!
XML布局如下:
java 代码部分:
报修历史出现了三次,我原本是要它出现一次的,望大神解决之!
![](http://img.bbs.csdn.net/upload/201412/24/1419353551_312492.jpg)
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);
}
}