android仿新浪微博随便看看

程序界面

源代码

布局

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#F0F8FF"
    android:orientation="horizontal" >

 
    <ImageView
        android:id="@+id/photo"
        android:padding="10dp"
        android:layout_width="48dp"
        android:layout_height="48dp" />


    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >


       <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >



            <TextView
                android:id="@+id/name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
         

            <TextView
                android:id="@+id/publish"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="right" />
        </LinearLayout>
   

        <TextView
            android:id="@+id/content"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>

</LinearLayout>

程序代码
public class MainActivity extends Activity {
	List<Map<String, ?>> data;
    ListView listView;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		data = getData();
		SimpleAdapter adapter = new SimpleAdapter(this, data,
				R.layout.list_item, new String[] { "photo", "name", "publish",
						"content" }, new int[] { R.id.photo, R.id.name,
						R.id.publish, R.id.content });
		listView=(ListView) this.findViewById(R.id.listView);
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(new ListClickHandler());

	}
	
	private class ListClickHandler implements OnItemClickListener{

		@Override
		public void onItemClick(AdapterView<?> adapterView, View view, int position,
				long id) {
			Map<String, String> item=(Map<String, String>) data.get(position);
			Toast.makeText(MainActivity.this, item.get("name").toString(), Toast.LENGTH_LONG).show();
		}
		
	}

	private List<Map<String, ?>> getData() {
		List<Map<String, ?>> data = new ArrayList<Map<String, ?>>();
		Map<String, Object> item = new HashMap<String, Object>();
		item.put("photo", R.drawable.p1);
		item.put("name", "楼下老王");
		item.put("publish", "10分钟前");
		item.put("content", "android好难");
		data.add(item);
		item = new HashMap<String, Object>();
		item.put("photo", R.drawable.p2);
		item.put("name", "举世独醒");
		item.put("publish", "15分钟前");
		item.put("content", "斗鱼好久没看了");
		data.add(item);
		item = new HashMap<String, Object>();
		item.put("photo", R.drawable.p3);
		item.put("name", "王尼玛");
		item.put("publish", "15分钟前");
		item.put("content", "爆米花手机全新发布");
		data.add(item);
		item = new HashMap<String, Object>();
		item.put("photo", R.drawable.p4);
		item.put("name", "longdd");
		item.put("publish", "20分钟前");
		item.put("content", "pv不应该被邀请");
		data.add(item);
		item = new HashMap<String, Object>();
		item.put("photo", R.drawable.p5);
		item.put("name", "蒙太奇");
		item.put("publish", "20分钟前");
		item.put("content", "炉石今天上2!");
		data.add(item);
		item = new HashMap<String, Object>();
		item.put("photo", R.drawable.p6);
		item.put("name", "若风");
		item.put("publish", "25分钟前");
		item.put("content", "今天真高兴啊!");
		data.add(item);
		item = new HashMap<String, Object>();
		item.put("photo", R.drawable.p7);
		item.put("name", "海涛");
		item.put("publish", "25分钟前");
		item.put("content", "小金本就是个骗局!");
		data.add(item);
		item = new HashMap<String, Object>();
		item.put("photo", R.drawable.p8);
		item.put("name", "皇叔");
		item.put("publish", "25分钟前");
		item.put("content", "魔兽今天又虐水友了");
		data.add(item);
		item = new HashMap<String, Object>();
		item.put("photo", R.drawable.p9);
		item.put("name", "安德罗妮");
		item.put("publish", "30分钟前");
		item.put("content", "板娘好久不直播了");
		data.add(item);
		item = new HashMap<String, Object>();
		item.put("photo", R.drawable.p10);
		item.put("name", "直播青铜杀鸡");
		item.put("publish", "30分钟前");
		item.put("content", "有钱就是任性");
		data.add(item);
		return data;
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值