Listview 中自定义加载布局文件

1、首选是是Activity_main.xml 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="
http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >
    <TextView
        android:id="@+id/tv"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="如下显示的listview列表"></TextView>
    <ListView
        android:id="@+id/lv"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
       
        ></ListView> 
        
    </LinearLayout>

 

2、需要SimpleDispatch中加载的布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="
http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
   
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        >
    <TextView
        android:id="@+id/tt1"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
        android:text=" "
        />
   
    <TextView
        android:id="@+id/tt2"
        android:layout_width="wrap_content"
       android:layout_height="wrap_content"
        android:text=" "
        />
    <TextView
        android:id="@+id/tt3"
        android:layout_width="wrap_content"
       android:layout_height="wrap_content"
        android:text=" "
        />
    </LinearLayout>
   
      <TextView
        android:id="@+id/tt4"
        android:layout_width="wrap_content"
       android:layout_height="wrap_content"
        android:text=" "
        />
 
 

</LinearLayout>

 

3、在MainActivity中直接操作如下

package com.example.teststyle;

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

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

public class MainActivity extends Activity {
 
// private ProgressBar progressBar;
// private Button bt;
 private TextView tv;
 private ListView lv;
 private List<Map<String, Object>> listadda = new ArrayList<Map<String, Object>>();  //适配器中存储数据

 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
        tv=(TextView)findViewById(R.id.tv);                                       
        lv=(ListView)findViewById(R.id.lv);                                           //listview控件
       for(int i=0;i<4;i++){                                                          //制造数据
        Map<String,Object> map=new HashMap<String, Object>();
         map.put("one", "发展人:");
         map.put("two", "河南大学");
         map.put("three", "成功交易"); 
         map.put("four", "流水"+i);
         listadda.add(map);
         }                                                                           //适配器中显示
       SimpleAdapter  simpleAdapter=new SimpleAdapter(this, listadda,R.layout.listviewone,    
         new String[]{"one","two","three","four"},new int[]{R.id.tt1,R.id.tt2,R.id.tt3,R.id.tt4});
       lv.setAdapter(simpleAdapter);
         
     
        }
  
       
    }
 
 

 

--------------------------------------------------------------------------------------------------------

 

如果大家感觉有写的有帮助,请留句话,表示一下谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值