模拟新浪微博随便看看栏目

模拟新浪微博随便看看栏目使用 ListView 来模仿微博随便看看栏 分析 nbsp 要完成这个效果 我们需要 nbsp 1 ListView 及 List ItrmextendsA 的编写 nbsp 2 定义数据集合 nbsp 3 创建 SimpleAdapte 绑定数据 nbsp 4 添加单击事件 nbsp 编码 MainActivity packagecom example androidweibo imp

模拟新浪微博随便看看栏目

使用ListView来模仿微博随便看看栏

【分析】

 

要完成这个效果,我们需要:

 

1.ListView及List_Itrm

extends Activity的编写

 2.定义数据集合 

3.创建SimpleAdapter绑定数据 

4.添加单击事件 

【编码】

MainActivity:

package com.example.androidweibo;

 private class ListClickHandler implements OnItemClickListener{

 private List
> getData() {


  List
> data = new ArrayList
>();

  Map

item = new HashMap

();

  item.put(“photo”, R.drawable.p1);
  item.put(“name”, “晓月”);
  item.put(“publish”, “1分钟前”);
  item.put(“content”, “正在学习AndroidListView,嘎嘎嘎嘎嘎嘎嘎嘎嘎”);
  data.add(item);
  item = new HashMap

();

  item.put(“photo”, R.drawable.p2);
  item.put(“name”, “张三”);
  item.put(“publish”, “10分钟前”);
  item.put(“content”, “今天真高兴啊!”);
  data.add(item);
  item = new HashMap

();

  item.put(“photo”, R.drawable.p3);
  item.put(“name”, “米粒”);
  item.put(“publish”, “2015—5-11”);
  item.put(“content”, “今天糗大了!”);
  data.add(item);
  item = new HashMap

();

  item.put(“photo”, R.drawable.p4);
  item.put(“name”, “高未”);
  item.put(“publish”, “2015—5-10”);
  item.put(“content”, “今天遇到一件好玩的事情!”);
  data.add(item);
  item = new HashMap

();

  item.put(“photo”, R.drawable.p5);
  item.put(“name”, “花花”);
  item.put(“publish”, “2015—5-10”);
  item.put(“content”, “今天天气真好哈!”);
  data.add(item);
  item = new HashMap

();

  item.put(“photo”, R.drawable.p6);
  item.put(“name”, “露露”);
  item.put(“publish”, “2015—5-9”);
  item.put(“content”, “今天真高兴啊!”);
  data.add(item);
  item = new HashMap

();

  item.put(“photo”, R.drawable.p7);
  item.put(“name”, “小新”);
  item.put(“publish”, “2015—5-9”);
  item.put(“content”, “我很开心今天!”);
  data.add(item);
  item = new HashMap

();

  item.put(“photo”, R.drawable.p8);
  item.put(“name”, “苏苏”);
  item.put(“publish”, “2015—5-8”);
  item.put(“content”, “世界好大啊!”);
  data.add(item);
  item = new HashMap

();

  item.put(“photo”, R.drawable.p9);
  item.put(“name”, “依晨”);
  item.put(“publish”, “2015—5-7”);
  item.put(“content”, “我今天买了一个大熊猫!”);
  data.add(item);
  return data;
 }




































































}

【布局】

activity_main.xml:

http://schemas.android.com/apk/res/android”

    xmlns:tools=”http://schemas.android.com/tools”
    android:id=”@+id/LinearLayout1″
    android:layout_width=”match_parent”
    android:layout_height=”match_parent”
    android:orientation=”vertical”
    android:background=”@android:color/holo_blue_bright”
    android:paddingBottom=”@dimen/activity_vertical_margin”
    android:paddingLeft=”@dimen/activity_horizontal_margin”
    android:paddingRight=”@dimen/activity_horizontal_margin”
    android:paddingTop=”@dimen/activity_vertical_margin”
    tools:context=”.MainActivity” >










            android:id=”@+id/listView”

        android:layout_width=”match_parent”
        android:layout_height=”match_parent” >
   


list_itrm.xml:

            android:layout_width=”match_parent”

        android:layout_height=”wrap_content”
        android:orientation=”vertical” >

       

                    android:layout_width=”fill_parent”

            android:layout_height=”wrap_content”
            android:orientation=”horizontal” >

           

           
                android:id=”@+id/name”

                android:textColor=”@android:color/black”
                android:layout_width=”wrap_content”
                android:layout_height=”wrap_content” />



           

           
                android:id=”@+id/publish”

                android:textColor=”@android:color/black”
                android:layout_width=”fill_parent”
                android:layout_height=”wrap_content”
                android:gravity=”right” />
       
       







       
            android:id=”@+id/content”

            android:textColor=”@android:color/black”
            android:layout_width=”wrap_content”
            android:layout_height=”wrap_content” />



 

 

 

 

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/209285.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月19日 上午9:36
下一篇 2026年3月19日 上午9:36


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号