在用LIST ACTIVITY时,如果自定义VIEW,采用setContentView()方法导入一个LAYOUT资源文件时,在这个资源文件的LISTVIEW部分的ID常采用:android:id="@+id/android:list",这是啥玩意呢?

首先可以先参考这篇文章,入下门吧。http://blog.sina.com.cn/s/blog_908e1e4a0100v2yj.html 其实,"@+id/android:list“对应的就是:ANDROID SDK 安装盘:\AndroidSDK\platforms\android-16\data\res\values下ids.xml文件中定义的ID资源了,也就是说,如果在LIST ACTIVITY中,如果要自己自定义LIST VIEW,那么,这个LIST VIEW的ID,应该要设置成为:"@+id/android:list"。

网上一些文章讲得比较明白了,不过我还是一知半解,经过自己的动手实践,总算搞明白了,在上面导入的LAYOUT资源文件中,我将LISTVIEW的ID改为”android:id="@+id/list"“,结果ECLIPSE的LOG CAT中用红色提示显示,可以看到下面灰色一行的英文提示:LSITVIEW的ID要为:android.R.id.list,而它就是:"@+id/android:list了,呵呵。下面是截图:

附上源代码吧,注意,运行后,就可以在LOG CAT中看到上面的红色提示了。

src部分:

package com.mobile.infos;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;

import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import android.widget.ListView;
import android.widget.AdapterView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Toast;
import android.util.Log;
import android.content.Intent;
import android.app.ListActivity;

public class MainActivity extends ListActivity {

private static final String TAG="eoeInforsAssistant";
List<Map<String,Object>> list;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_main);
refreshListItems();

}

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

private void refreshListItems()
{
list=BuildListForSimpleAdapter();
SimpleAdapter notes=new SimpleAdapter(this,list,R.layout.item_row,
new String[]{"name","desc"},new int[]{R.id.name,R.id.desc});
this.setListAdapter(notes);

}

private List<Map<String,Object>> BuildListForSimpleAdapter()
{
List<Map<String,Object>>list=new ArrayList<Map<String,Object>>(3);
Map<String,Object> map=new HashMap<String,Object>();
map.put("name", "系统信息");
map.put("desc", "查看设备系统版本,运行商以及系统信息");
list.add(map);

map=new HashMap<String,Object>();
map.put("name", "硬件信息");
map.put("desc", "查看设备硬件信息");
list.add(map);

map=new HashMap<String,Object>();
map.put("name", "软件信息");
map.put("desc", "查看软件信息");
list.add(map);

map=new HashMap<String,Object>();
map.put("name", "运行时信息");
map.put("desc", "查看设备设备运行时信息");
list.add(map);

map=new HashMap<String,Object>();
map.put("name", "文件浏览器");
map.put("desc", "浏览查看文件");
list.add(map);
return list;
}
}

Layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/list">
</ListView>
</LinearLayout>

更多相关文章

  1. NPM 和webpack 的基础使用
  2. 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
  3. Android如何调用第三方SO库
  4. android使用google map api
  5. android的调试技巧,尤其是nativec等底层程序
  6. Android: NDK编程入门笔记
  7. Flutter 项目打包发布
  8. Android(安卓)学习笔记【基础扫盲篇】
  9. Android插件化开发之DexClassLoader动态加载dex、jar小Demo

随机推荐

  1. Android NullPointerException解决方法
  2. 10个android开源项目
  3. 十大Android IDE工具和应用
  4. Android开发平台Android Studio学习之一(
  5. 【原创】Android锁定横竖屏、splash,全屏
  6. Android常用的基本控件
  7. Android -- 图像处理(信息量超大)
  8. Android中Intent习惯用法
  9. Android(安卓)获取包名,版本信息及Version
  10. API Demos 2.3 学习笔记 (4)-- Text->Lin