GridView

  private GridView gv_2;
    private GridView gv_1;
    private List<String> list;
    private List<String> lists;
 

        gv_1=(GridView)findViewById(R.id.gv_1);
        gv_2=(GridView)findViewById(R.id.gv_2);
        initData();
        gv_1.setAdapter(new MyAdapter(this,list));
        gv_2.setAdapter(new MyAdapter(this,lists));
    }

    private void initData() {
        list=new ArrayList<String>() ;
        lists=new ArrayList<String>() ;
        for (int i=0;i<24;i++){
            list.add("测试数据"+i);
            lists.add("+测试数据"+i);
        }

    }
}
====================================================================
public class MyAdapter extends BaseAdapter{

    private Context con;
    private List<String> list;

    public MyAdapter(Context con,List<String> list) {
        this.con = con;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView==null){
            convertView=View.inflate(con, R.layout.layout_xx1,null);
            holder=new ViewHolder();
            holder.but=(Button) convertView.findViewById(R.id.but);
            convertView.setTag(holder);
        }else {
            holder=(ViewHolder)convertView.getTag();
        }
        holder.but.setText(list.get(position).toString());
        return convertView;
    }
    public class ViewHolder{
        private Button but;
    }
}
===========================================================================
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" tools:context="com.example.day19_20171220.MainActivity">

    <TextView
        android:layout_weight="1"
        android:text="我的频道"
        android:textSize="35dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <GridView
        android:numColumns="4"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="6"
        android:id="@+id/gv_1"></GridView>
    <TextView
        android:layout_weight="1"
        android:text="频道推荐"
        android:textSize="35dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <GridView
        android:numColumns="4"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="6"
        android:id="@+id/gv_2"></GridView>

</LinearLayout>
======================================================================================
 
layout_xx1.xml
 
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/but"/>
</LinearLayout>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值