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


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值