位置: 编程技术 - 正文

模拟新浪微博随便看看(模拟新浪微博用户注册程序设计)

编辑:rootadmin

推荐整理分享模拟新浪微博随便看看(模拟新浪微博用户注册程序设计),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:模拟微博的软件,新浪微博模拟生成器,发微博模拟器,发微博模拟器,发微博模拟器,新浪微博模拟生成器,新浪微博模拟生成器,新浪微博模拟登录,内容如对您有帮助,希望把文章链接给更多的朋友!

1.运行效果图

2.目的:

1)对LIstView 控件的使用

2)理解Adapter的作用并掌控自定义FruitAdapter的使用方法

3.步骤:

1)extends Activity

2)定义数据集合

3)创建SimpleAdapter绑定数据

4)添加单击事件

4.xml布局:

1)在res/value下建立mytitlebar.xml文件

代码如下:

<?xml version="1.0" encoding="utf-8"?><resources xmlns:android=" <style name="myTitleBg"> <item name="android:background">#FF</item> </style> <style name="myTheme" parent="android:Theme"> <item name="android:windowNoTitle">false</item> <item name="android:windowTitleSize">dp</item>

<item name="android:windowTitleBackgroundStyle">@style/myTitleBg</item> </style> </resources>

2)修改AndroidManifest.xml文件

android:theme="@style/myTheme"

3)添加两个xml文件:activity_main.xml

模拟新浪微博随便看看(模拟新浪微博用户注册程序设计)

代码如下:

<RelativeLayout xmlns:android=" xmlns:tools=" android:layout_width="fill_parent" android:layout_height="fill_parent" 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" > <ListView android:id="@&#;id/listView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" > </ListView></RelativeLayout>

list_item.xml

代码如下:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" > <!-- 左边图片 --> <ImageView android:id="@&#;id/photo" android:padding="dp" android:layout_width="dp" android:layout_height="dp" /> <!-- 右边布局 --> <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>

5.java代码:

package cn.bzu.edu.weibo;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import android.os.Bundle;import android.app.Activity;import android.view.Menu;import android.view.View;import android.widget.AdapterView;import android.widget.AdapterView.OnItemClickListener;import android.widget.ListView;import android.widget.SimpleAdapter;import android.widget.Toast;//第一步:extends Activitypublic class MainActivity extends Activity {// 第二步:定义数据集合List<Map<String,?>> data;ListView listview; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); data = getdata(); // 第三步:创建SimpleAdapter绑定数据 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{ 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", "1分钟前"); item.put("content", "温暖如 春"); data.add(item); item=new HashMap<String, Object>(); item.put("photo", R.drawable.p2); item.put("name", "二月"); item.put("publish", "2分钟前"); item.put("content", "草长莺飞"); data.add(item); item=new HashMap<String, Object>(); item.put("photo", R.drawable.p3); item.put("name", "三月"); item.put("publish", "3分钟前"); item.put("content", "乱花渐欲迷人&#;"); data.add(item); item=new HashMap<String, Object>(); item.put("photo", R.drawable.p4); item.put("name", "四月"); item.put("publish", "4分钟前"); item.put("content", "你是人间的四月天"); data.add(item); item=new HashMap<String, Object>(); item.put("photo", R.drawable.p5); item.put("name", "五月"); item.put("publish", "5分钟前"); item.put("content", "温馨五月天"); data.add(item); item=new HashMap<String, Object>(); item.put("photo", R.drawable.p6); item.put("name", "六月"); item.put("publish", "6分钟前"); item.put("content", "天微蓝,真美"); data.add(item); item=new HashMap<String, Object>(); item.put("photo", R.drawable.p7); item.put("name", "七月"); item.put("publish", "7分钟前"); item.put("content", "我怀念那个夏天的午后 彩虹映着我们的笑脸 雨过后白云挂满天 "); data.add(item); item=new HashMap<String, Object>(); item.put("photo", R.drawable.p8); item.put("name", "八月"); item.put("publish", "8分钟前"); item.put("content", "八月十五月儿圆"); data.add(item); item=new HashMap<String, Object>(); item.put("photo", R.drawable.p9); item.put("name", "九月"); item.put("publish", "9分钟前"); item.put("content", "你好"); data.add(item); item=new HashMap<String, Object>();// TODO Auto-generated method stub return data;}@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }

Android xml 小技巧 拦截默认的选焦点Viewandroid:focusable="true"android:focusableInTouchMode="true"android:layout_height="0px"android:layout_width="0px"/View

a大叔大叔的 -------ahref=

Android ADT 无法更新到.0.2问题解决方案 转载:

本文链接地址:https://www.jiuchutong.com/biancheng/379666.html 转载请保留说明!

上一篇:Android spinner 的使用

下一篇:Android xml 小技巧(android binary xml)

免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

鄂ICP备2023003026号

网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

友情链接: 武汉网站建设 电脑维修 湖南楚通运网络