- 浏览: 41267 次
- 性别:
- 来自: 济南
最新评论
-
kensunhu:
正是我想要的。典型的app ui布局。谢谢!
android UI - 仿威信tab样式 -
007007jing:
bing_zz 写道兄弟加油!谢谢
android2.3 api demo 学习系列(7)--App/Activity/Hello World -
bing_zz:
兄弟加油!
android2.3 api demo 学习系列(7)--App/Activity/Hello World
android最有价值的参考资料莫过于sdk提供的apidemos,现在我们就开始一点一点的学习,本人水平有限,文章中出现错误请您指正。
sdk中得apidemos接近200个,设计到android的各个方面,首先先学习下android的开发人员如何将这200多个demo分类的。
1、首先在AndroidManifest.xml注册activity时附件以下intent-filter 例如
<activity android:name=".app.Animation" android:label="@string/activity_animation"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="com.angie.apidemos.SAMPLE_CODE" /> </intent-filter> </activity>
2、在values/Strings.xml 声明该activity的label值 (这样声明是为了下面的list分类)
<string name="activity_animation">App/Activity/Animation</string>
3、最后在自己的activity里面处理list
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //获取传递进来的附加信息 Intent intent = getIntent(); String path = intent.getStringExtra("com.angie.apidemos.Path"); if (path == null) { path = ""; } //create list setListAdapter(new SimpleAdapter(this, getData(path), R.layout.mainlist, new String[] { "image", "title" }, new int[] { R.id.rowImage, R.id.rowTitle })); getListView().setTextFilterEnabled(true); } protected List getData(String prefix) { List<Map> myData = new ArrayList<Map>(); //获取符合条件的activity (包含其他应用程序符合条件的activity) Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(MyApplication.CATEGORY_SAMPLE_CODE); PackageManager pm = getPackageManager(); List<ResolveInfo> list = pm.queryIntentActivities(mainIntent, 0); if (null == list) return myData; String[] prefixPath; if (prefix.equals("")) { prefixPath = null; } else { prefixPath = prefix.split("/"); } int len = list.size(); Map<String, Boolean> entries = new HashMap<String, Boolean>(); for (int i = 0; i < len; i++) { ResolveInfo info = list.get(i); CharSequence labelSeq = info.loadLabel(pm); String label = labelSeq != null ? labelSeq.toString() : info.activityInfo.name; if (prefix.length() == 0 || label.startsWith(prefix)) { String[] labelPath = label.split("/"); String nextLabel = prefixPath == null ? labelPath[0] : labelPath[prefixPath.length]; if ((prefixPath != null ? prefixPath.length : 0) == labelPath.length - 1) { addItem(myData, nextLabel, activityIntent( info.activityInfo.applicationInfo.packageName, info.activityInfo.name), R.drawable.launcher); } else { if (entries.get(nextLabel) == null) { addItem(myData, nextLabel, browseIntent(prefix.equals("") ? nextLabel : prefix + "/" + nextLabel),R.drawable.list); entries.put(nextLabel, true); } } } } Collections.sort(myData, sDisplayNameComparator); return myData; } private final static Comparator<Map> sDisplayNameComparator = new Comparator<Map>() { private final Collator collator = Collator.getInstance(); public int compare(Map map1, Map map2) { return collator.compare(map1.get("title"), map2.get("title")); } }; protected Intent activityIntent(String pkg, String componentName) { Intent result = new Intent(); result.setClassName(pkg, componentName); return result; } protected Intent browseIntent(String path) { Intent result = new Intent(); result.setClass(this, ApiDemosStudyActivity.class); result.putExtra("com.angie.apidemos.Path", path); return result; } protected void addItem(List<Map> data, String name, Intent intent, int image) { Map<String, Object> temp = new HashMap<String, Object>(); temp.put("image", image); temp.put("title", name); temp.put("intent", intent); data.add(temp); } @Override protected void onListItemClick(ListView l, View v, int position, long id) { Map map = (Map) l.getItemAtPosition(position); Intent intent = (Intent) map.get("intent"); startActivity(intent); }
4、上面的代码没有特别难理解的地方,故不再一一注释。其中用到的mainlist定义如下
<?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="wrap_content" android:gravity="center_vertical" android:orientation="horizontal"> <ImageView android:id="@+id/rowImage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_vertical" android:paddingLeft="6dip" android:src="@drawable/list" /> <TextView android:id="@+id/rowTitle" android:layout_width="match_parent" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:gravity="center_vertical" android:paddingLeft="6dip" android:minHeight="?android:attr/listPreferredItemHeight"/> </LinearLayout>
注:代码中用到的drawable资源请自行导入,不再赘述。
其中用到的MyApplication类主要是想定义一个CATEGORY_SAMPLE_CODE,你也可以放弃这种方式 直接使用intent内部定义的CATEGORY。代码示例如下
public class MyApplication extends Application { public static final String CATEGORY_SAMPLE_CODE = "com.angie.apidemos.SAMPLE_CODE"; /* (non-Javadoc) * @see android.app.Application#onCreate() */ @Override public void onCreate() { // TODO Auto-generated method stub super.onCreate(); } }
效果图:
发表评论
-
android2.3 api demo 学习系列(23)--App/Notification/StatusBarNotification
2012-07-07 19:51 1300apidemo-StatusBarNotification里面 ... -
android2.3 api demo 学习系列(22)--App/Notification/Notifying Service Controller
2012-07-06 14:56 1674因为还没有看到service的demo,这里先不对servic ... -
android2.3 api demo 学习系列(21)--App/Notification/Incoming Message
2012-07-06 11:55 2427现在我们开始学习android的Status Bar Noti ... -
android2.3 api demo 学习系列(20)--App/Menu
2012-07-06 09:58 1114现在来学习下menu的相关 ... -
android2.3 api demo 学习系列(19)--App/Intent and Launcher Shortcuts
2012-07-06 09:36 1062第一个demo:Intent,根据指定的类型,枚举出所有符合条 ... -
android2.3 api demo 学习系列(18)--App/Dialog
2012-07-06 09:13 958今天主要学习Dialog: 1、一般的dialog ... -
android2.3 api demo 学习系列(17)--App/Alarm/AlarmController and Alarm Service
2012-07-03 17:12 2146本次学习将apidemo中得两个demo:AlarmContr ... -
android2.3 api demo 学习系列(16)--App/Activity/Translucent and Blur activity
2012-07-03 11:47 1855本次同样是将apidemo中得两个demo合并起来学习:Tra ... -
android2.3 api demo 学习系列(15)--App/Activity/SetWallpaper
2012-07-03 11:00 1092本次示例我们整合了apidemo里面的两个demo:SetWa ... -
android2.3 api demo 学习系列(14)--App/Activity/Screen Orientation
2012-07-03 09:50 3081下面我们来学习下Screen Orientaiton的demo ... -
android2.3 api demo 学习系列(13)--App/Activity/Save & Restore
2012-07-02 17:29 1437前面文章android2.3 api demo 学习系 ... -
android2.3 api demo 学习系列(12)--App/Activity/Reorder Activitys
2012-07-02 16:45 960Reorder Activitys Demo主要是实现打开ac ... -
android2.3 api demo 学习系列(11)--App/Activity/Redirection
2012-07-02 15:52 831APIDEMO里面的redirection示例本身并没有新技术 ... -
android2.3 api demo 学习系列(10)--App/Activity/RecevieResult
2012-07-02 14:48 959在先前的文章 activity之间跳转传值 已经学习过这方面的 ... -
android2.3 api demo 学习系列(9)--App/Activity/QuickContactsDemo
2012-07-01 19:46 959现在我们来学习如何使用Content Provider来访问a ... -
android2.3 api demo 学习系列(8)--App/Activity/Preference State
2012-07-01 19:45 870android保存数据有很多种方式,其中最简单的就是使用Sha ... -
android2.3 api demo 学习系列(7)--App/Activity/Hello World
2012-06-29 14:03 1049学习android当然不能少了HelloWorld,接下来我们 ... -
android2.3 api demo 学习系列(6)--App/Activity/ForwardActivity
2012-06-29 13:50 799本次学习activity的跳转 1、构建intent ... -
android2.3 api demo 学习系列(5)--App/Activity/Dialog
2012-06-29 11:42 970前面我们已经学习了Custom Dialog 和 Custom ... -
android2.3 api demo 学习系列(4)--App/Activity/Custom Title
2012-06-29 11:26 1055android的标题栏默认是由android:lable定义的 ...
相关推荐
Google官方API(Android-12 ApiDemo)
Google官方API(Android-7 ApiDemo)
Google官方API(Android-14 ApiDemo)
Google官方API(Android-13 ApiDemo)
android api demo android初级的全部demo,各种组件的使用demo
Google官方API(Android-10 ApiDemo)
Google官方API(Android-15 ApiDemo)
8080端口,http://localhost:8080/employee/save?id=1&name=""&sex=""&major=""的访问接口 数据库名必须为yunserver,表名employe,存在账号root admin
android api demo apidemo 示例
Android2.3ApiDemo
Google官方API(Android ApiDemo) 打包下载,初学者学习的捷径
把Android Apidemo第一个例子抽出来,以后每学一节就加进Apidemo框架里,加深理解
Android官方apidemo,android studio直接导入,运行安装即可
关于超低功耗蓝牙(BLE)4.0的android应用开发,通过应用博通的API,可以方便轻松的实现android应用程序的蓝牙通信;
android sdk中拿出来的 android api demo,sdk\samples\android-17,给需要的人
学习android 的sample apidemo 以后要用到这些例子 方便自己方便别人
android ApiDemo android ApiDemo
Api-demo.zip,API平台的演示应用程序框架API平台演示,一个api可以被认为是多个软件设备之间通信的指导手册。例如,api可用于web应用程序之间的数据库通信。通过提取实现并将数据放弃到对象中,api简化了编程。
这是一个kb网API对接demo