初学者-android开发-listview 分隔线问题 及自定义item

写本文主要是做个学习笔记,自己用的时间不至于白白浪费

如果要显示有规律的查询结果,一般用的是listview

下面是自定义的listivew 中的item 文件 ,名字叫home_tab1_gtkd_query_list.xml

<pre name="code" class="html"><?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="10dp"
    xmlns:android="http://schemas.android.com/apk/res/android"
    >
    <TextView android:layout_width="wrap_content" 
        android:textSize="18dp" 
        android:textColor="#228fbd" 
        android:id="@+id/item_top" 
        android:layout_height="30dp" 
        android:layout_alignParentLeft="true" 
        android:layout_alignParentTop="true" 
        android:layout_marginLeft="10dp" android:layout_marginTop="10dp"></TextView>
    <TextView android:layout_width="wrap_content" 
        android:textColor="#999999" 
        android:id="@+id/item_top_right" 
        android:layout_height="wrap_content" 
        android:layout_alignParentRight="true" 
        android:layout_alignParentTop="true" 
        android:layout_marginRight="10dp" 
        android:layout_marginTop="10dp"/>
	<TextView android:layout_width="fill_parent"  android:textColor="#999999" android:id="@+id/item_bottom" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" 
	    android:layout_marginTop="38dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp"></TextView>
	
</RelativeLayout>

 如果要显示一个自定义的listview,对其进行多个属性的调整,本人用的方法是,新建一个layout 文件 list_view.xml  

代码如下 

<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:divider="#dddddd"  <!-- 配置分隔线颜色的地方,连同下面的dividerheight属性要一起写上,这样才能看到效果,这个问题害惨我了-->
    android:dividerHeight="1px"  
    android:id="@+id/listview" >
</ListView>
最后要做的就是建一个activity

package com.hyjy.crhe.third;

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

import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONObject;

import com.hyjy.crhe.Gic;
import com.hyjy.crhe.R;
import com.hyjy.util.Util;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class GtkdQueryResult extends Activity {
   @Override
	protected void onCreate(Bundle savedInstanceState) {
	   StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()  
	       .detectDiskReads()  
	       .detectDiskWrites()  
	       .detectNetwork()  
	       .penaltyLog()  
	       .build());  
   StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()  
	       .detectLeakedSqlLiteObjects()  
	       .penaltyLog()  
	       .penaltyDeath()  
	       .build());
<span style="white-space:pre">		</span>//以上用来连接网络,之前在manifest中配置了网络的权限,但仍不能访问网络,最后写了上面 这段代码才可以

		 
		super.onCreate(savedInstanceState);
		 
		setContentView(R.layout.list_view);//加载视图,用到上面建的那个list_view了
		 
		ListView listview=(ListView)findViewById(R.id.listview);//在这个list_view中找到listview,
		Intent intent=this.getIntent();
		
		String billcode=intent.getStringExtra("billcode");
		
		String json=new Util().getJsonString_request(Gic.gtkd_url+"?billcode="+billcode);//访问接口,得到返回数据
		
		try{
			JSONObject result = new JSONObject(json);
			
			SimpleAdapter adapter = new SimpleAdapter(this,getData(result),R.layout.home_tab1_gtkd_query_list,
			new String[]{"item_top","item_top_right","item_bottom"},
			new int[]{R.id.item_top,R.id.item_top_right,R.id.item_bottom});
			listview.setAdapter(adapter);//将listview加载数据
			
		}catch(Exception e){
			 
		}
		
	}
//解析接口返回的数据,以list返回
   private List<Map<String, String>> getData(JSONObject result) {
	   List<Map<String, String>> list = new ArrayList<Map<String, String>>();
           //代码根据自己的业务去写
<span style="white-space:pre">	</span>   return list;
	
    
 }
}

 



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值