android 自定义View
When you use a custom view in aListView
you must define the row layout. You create an xml where you place android widgets and then in the adapter's code you have to do something like this:
public MyAdapter(Context context, List<MyObject> objects) { super(context, 1, objects); /* We get the inflator in the constructor */ mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Override public View getView(int position, View convertView, ViewGroup parent) { View view; /* We inflate the xml which gives us a view */ view = mInflater.inflate(R.layout.my_list_custom_row, parent, false); /* Get the item in the adapter */ MyObject myObject = getItem(position); /* Get the widget with id name which is defined in the xml of the row */ TextView name = (TextView) view.findViewById(R.id.name); /* Populate the row's xml with info from the item */ name.setText(myObject.getName());
}
更多相关文章
- 代码中设置drawableleft
- android 3.0 隐藏 系统标题栏
- Android开发中activity切换动画的实现
- Android(安卓)学习 笔记_05. 文件下载
- Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
- 技术博客汇总
- android 2.3 wifi (一)
- AndRoid Notification的清空和修改
- Android中的Chronometer