新浪微博开发(五)AppList界面
来源:互联网 发布:手机端淘宝怎么写代码 编辑:程序博客网 时间:2024/06/13 00:46
这是客户端开发部分很重要的一个类,但是在开发之前需要用到有关GridView的知识。
若要临时充充电,请移步:GridView(九宫图)的使用介绍。
下面是AppList类的代码:
/* * 用来显示、管理自己的微博账号,包括新浪微博账号,腾讯微博账号等 * 为了更好地阅读本代码,需要向你介绍的是:AppList类使用两个xml文件。、 * 一个是sina_applist.xml;一个是sina_applist_component.xml * sina_applist.xml含有一个gridView布局文件和一个位于界面右下端的返回按钮,这个按钮是ImageButton * sina_applist_component.xml是上个文件中GridView组件中的两个组件,用来实现显示图像的功能 */package tianyi.sina;import java.util.ArrayList;import java.util.HashMap;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.AdapterView;import android.widget.AdapterView.OnItemClickListener;import android.widget.GridView;import android.widget.ImageView;import android.widget.SimpleAdapter;import android.widget.Toast;public class AppList extends Activity {GridView gridView;ImageView returnButton;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);// 调用gridView布局,表现效果是以九宫格的形式显示App的图标setContentView(R.layout.sina_applist);gridView = (GridView) findViewById(R.id.sina_applist_gridview);// 生成动态数组,并且转入数据ArrayList<HashMap<String, Object>> lstImageItem = new ArrayList<HashMap<String, Object>>();// 向map中添加图片for (int i = 0; i < 7; i++) {HashMap<String, Object> map = new HashMap<String, Object>();if (i == 0) {map.put("itemImage", R.drawable.sina);map.put("itemText", "新浪微博");}if (i == 1) {map.put("itemImage", R.drawable.tencent);map.put("itemText", "腾讯微博");}if (i == 2) {map.put("itemImage", R.drawable.twitter);map.put("itemText", "twitter");}if (i == 3) {map.put("itemImage", R.drawable.net);map.put("itemText", "网易");}if (i == 4) {map.put("itemImage", R.drawable.tt);map.put("itemText", "天涯");}if (i == 5) {map.put("itemImage", R.drawable.dou);map.put("itemText", "豆瓣");}if (i == 6) {map.put("itemImage", R.drawable.renren);map.put("itemText", "人人网");}lstImageItem.add(map);}// 生成适配器的ImageItem <====> 动态数组的元素,两者一一对应SimpleAdapter saImageItems = new SimpleAdapter(this, // 没什么解释lstImageItem,// 数据来源R.layout.sina_applist_component, new String[] { "itemImage","itemText" }, new int[] {R.id.sina_applist_componet_ItemImage,R.id.sina_applist_componet_ItemText });// 添加并且显示gridView.setAdapter(saImageItems);// 添加消息处理gridView.setOnItemClickListener(new ItemClickListener());// 调用在sina_applist.xml文件中的returnButtonreturnButton = (ImageView) findViewById(R.id.sina_applis_imageButton1);returnButton.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stub// 返回到登录界面Intent intent = new Intent(AppList.this, SinaActivity.class);startActivity(intent);finish();}});}// 当AdapterView被单击(触摸屏或者键盘),则返回的Item单击事件class ItemClickListener implements OnItemClickListener {/* * AdapterView.OnItemClickListener(AdapterView<?> parent, View view, int position, long id) * parentThe AdapterView where the click happened.viewThe view within the AdapterView that was clicked (this will be a view provided by the adapter)positionThe position of the view in the adapter.idThe row id of the item that was clicked.*/ @Overridepublic void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {// 从注释中可以看到arg2是被选中的view在适配器中的位置Object obj = gridView.getAdapter().getItem(arg2);HashMap<String, Object> map = (HashMap<String, Object>) obj;String str = (String) map.get("itemText");if (str.equals("新浪微博")) {//对于OauthUtils类的详细介绍参见下一篇文章OauthUtils oauthUtils = OauthUtils.getInstance();oauthUtils.initSinaData();Intent intent = new Intent(AppList.this, AuthorActivity.class);startActivity(intent);} else if (str.equals("腾讯微博")) {//对于OauthUtils类的详细介绍参见下一篇文章OauthUtils oauthUtils = OauthUtils.getInstance();oauthUtils.initQQData();Intent intent = new Intent(AppList.this, AuthorActivity.class);startActivity(intent);}else if (str.equals("twitter")) {} else if (str.equals("网易")) {} else if (str.equals("天涯")) {} else if (str.equals("豆瓣")) {} else if (str.equals("人人网")) {}}}}
AppList界面的效果图以及开发中要使用到的图标:
另外两个XML文件代码如下:
sina_applist.xml
<?xml version="1.0" encoding="utf-8"?><!--介绍一下里面的某些属性:android:numColumns="auto_fit" ,GridView的列数设置为自动android:columnWidth="90dp",每列的宽度,也就是Item的宽度android:stretchMode="columnWidth",缩放与列宽大小同步android:verticalSpacing="10dp",两行之间的边距,如:行一(NO.0~NO.2)与行二(NO.3~NO.5)间距为10dpandroid:horizontalSpacing="10dp",两列之间的边距。--><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingBottom="4dip" > <GridView android:id="@+id/sina_applist_gridview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:columnWidth="90dp" android:gravity="center" android:horizontalSpacing="10dp" android:numColumns="auto_fit" android:stretchMode="columnWidth" android:verticalSpacing="10dp" /> <ImageButton android:id="@+id/sina_applis_imageButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:src="@drawable/returntowel" /></RelativeLayout>sina_applist_component.xml:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingBottom="4dip" > <ImageView android:id="@+id/sina_applist_componet_ItemImage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" > </ImageView> <TextView android:id="@+id/sina_applist_componet_ItemText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/sina_applist_componet_ItemImage" android:layout_centerHorizontal="true" android:text="TextView01" > </TextView> </RelativeLayout><!-- 这里面定义的两个组件将会被应用到sina_applist.xml中的GridView组件使用,作为显示数据的两个参数-->
完成了界面的开发工作,我们就正式进入了学习新浪SDK中新的接口、新类及类的各种参数的阶段。
这个阶段也就是你最感兴趣的Oauth开发阶段。其实并不像你想象中的那样难,只不过是你需要重新学习一下新的类和接口而已,既然你能学会java中那么多类和接口的用法,这些类同样不在话下。
在下一篇文章中,是关于一个Oauth工具类(OauthUtils类)的内容,这个类为今后将要使用到的Oauth类和其他类提供了要调用的方法和参数。
- 新浪微博开发(五)AppList界面
- Sencha Touch开发实例:新浪微博iPhone界面
- 新浪微博开发之主程序界面的实现
- Android模仿新浪微博(启动界面&登陆界面)
- 新浪微博开发(四)微博客户端第一个界面
- 模拟新浪微博界面
- Android新浪微博开发(五)android中的selector,背景选择器
- Android新浪微博开发(五)Handler的用途,Android多线程编程
- 新浪微博开放平台站内应用开发流程直播(五)
- 新浪微博开发五(导航栏功能的实现)
- Android新浪微博客户端(五)——主界面的TabHost和WeiboUtil
- ListView组件的应用(模拟新浪微博界面)
- Android模仿新浪微博(oauth2.0授权界面)
- Android模仿新浪微博(分页管理界面)
- Android模仿新浪微博(写微博界面)
- Android模仿新浪微博(个人信息界面及其他)
- 新浪微博数据采集界面
- (droid分享)新浪微博开发系列【四】之登录界面
- CvArr CvMat IplImage 三种数据类型
- Application Security Logging
- Android build.prop生成过程
- 一个死锁的问题
- MFC 更改系统图标
- 新浪微博开发(五)AppList界面
- STL经典算法集锦<五>之查找(lower_bound/upper_bound/binary_search)
- 常用软件-svn客户端
- 字符串的输入注意
- oracle中to_date格式
- poj 3017 Cut the Sequence
- 蚂蚁与蚱蜢(The Ant and the Grasshopper)
- 2mat介绍
- 字符设备驱动归纳小结