- 浏览: 3905319 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
hinuliba:
...
字体背景颜色的高度修改 -
KANGOD:
最后的 -createDialog() 私有方法是怎么回事,没 ...
简单的实现listView中item多个控件以及点击事件 -
sswangqiao:
呵呵,呵呵
onActivityResult传值的使用 -
yumeiqiao:
感觉你所的不清楚 lstView.setOnTouchLi ...
listview中viewflipper的问题 -
lizhou828:
果然是大神啊!!!
Animation动画效果的实现
定义一个对象:
public class Weather { public static final int NA = -1; public static final int SUNNY = 0; public static final int OVERCAST = 1; public static final int RAIN = 2; public String city = null; public int temperature = 0; public int sky = NA; public Weather( String city, int temperature, int sky ) { this.city = city; this.temperature = temperature; this.sky = sky; } public String getCity() { return city; } public int getTemperature() { return temperature; } public int getSkyResource() { switch( sky ) { case SUNNY: return R.drawable.weather_sunny; case OVERCAST: return R.drawable.weather_overcast; case RAIN: return R.drawable.weather_rain; } return R.drawable.unknown; } }
主activity
public class CustomAdapterActivity extends ListActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ArrayList<Weather> weatherList = new ArrayList<Weather>(); Weather w = new Weather( "London", 17, Weather.OVERCAST ); weatherList.add( w ); w = new Weather( "Paris", 22, Weather.OVERCAST ); weatherList.add( w ); w = new Weather( "Athens", 29, Weather.SUNNY ); weatherList.add( w ); w = new Weather( "Stockholm", 12, Weather.RAIN ); weatherList.add( w ); WeatherAdapter weatherAdapter = new WeatherAdapter( this, weatherList ); setListAdapter( weatherAdapter ); } }
最关键的就是 WeatherAdapter
class WeatherAdapterView extends LinearLayout { public static final String LOG_TAG = "WeatherAdapterView"; public WeatherAdapterView(Context context, Weather weather ) { super( context ); this.setOrientation(HORIZONTAL); LinearLayout.LayoutParams cityParams = new LinearLayout.LayoutParams(100, LayoutParams.WRAP_CONTENT); cityParams.setMargins(1, 1, 1, 1); TextView cityControl = new TextView( context ); cityControl.setTextAppearance( context, R.style.SpecialText ); cityControl.setText( weather.getCity() ); addView( cityControl, cityParams); LinearLayout.LayoutParams temperatureParams = new LinearLayout.LayoutParams(20, LayoutParams.WRAP_CONTENT); temperatureParams.setMargins(1, 1, 1, 1); TextView temperatureControl = new TextView(context); temperatureControl.setText( Integer.toString( weather.temperature ) ); addView( temperatureControl, temperatureParams); LinearLayout.LayoutParams skyParams = new LinearLayout.LayoutParams(25, LayoutParams.WRAP_CONTENT); ImageView skyControl = new ImageView( context ); Log.d( LOG_TAG, weather.getCity()+" -> "+weather.sky ); skyControl.setImageResource( weather.getSkyResource() ); addView( skyControl, skyParams ); } } public class WeatherAdapter extends BaseAdapter { private Context context; private List<Weather> weatherList; public WeatherAdapter(Context context, List<Weather> weatherList ) { this.context = context; this.weatherList = weatherList; } public int getCount() { return weatherList.size(); } public Object getItem(int position) { return weatherList.get(position); } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { Weather weather = weatherList.get(position); return new WeatherAdapterView(this.context, weather ); } }
通过定义一个对象 在这个对象中包含要显示的东西,这样就不用使用simpleAdapater了,不同的方法自己选择吧。
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="MyTheme" parent="android:Theme.Light"> <item name="android:listViewStyle">@style/MyListView</item> </style> <style name="SpecialText" parent="@android:style/TextAppearance"> <item name="android:textSize">18sp</item> <item name="android:textStyle">bold</item> <item name="android:textColor">#008</item> </style> <style name="MyListView" parent="@android:style/Widget.ListView"> <item name="android:background">@color/opaque_red</item> <item name="android:listSelector">@drawable/z_selector_background</item> </style> </resources>
别忘了在主xml中加入上面的主题。
源文件上传了 这里面也使用到了selector
- CustomAdapterActivity.rar (63.3 KB)
- 下载次数: 336
发表评论
-
URI 转path
2019-06-26 10:41 1230转自知乎Matisse package com.zhihu ... -
权限申请
2017-09-22 13:25 1228public class PermissionActivit ... -
onPreviewFrame 相机输出格式转换yuv420p保存成图片
2015-11-25 15:59 7489在最近项目中,因为特殊需要,底层相机往外输出了i420 也 ... -
new Android's Runtime Permission
2015-11-03 21:05 1196targetSdkVersion 23 开始 使用运行时权 ... -
自定义listview 边缘效果
2015-02-28 10:58 1704static void ChangeEdgeEffect( ... -
发射打开wifi
2015-01-07 10:25 1377WifiManager wifiManager = (Wif ... -
RecyclerView
2014-11-05 13:08 1218http://www.grokkingandroid.com ... -
获取点击区域
2014-04-28 09:39 1523@Override public void getHitR ... -
speex 和libogg 编译
2014-04-03 16:17 6371下载: http://www.speex.org/down ... -
rsync 同步
2014-03-28 17:06 1804两台android 设备 进行rsy ... -
流转字符串
2014-03-11 09:49 1479public static String convertSt ... -
java simplexml 序列化
2014-03-06 13:22 5887<?xml version="1.0&quo ... -
获取其他程序的特定资源
2014-03-05 09:33 1660try { PackageManager man ... -
检测来电属于哪个sim卡
2014-02-07 10:41 1677public class IncomingCallInter ... -
使用 NDK r9 编译ffmpeg
2014-01-16 13:32 167701. 环境 ubuntu 我的是13.10 ndk r9 ... -
android h264含so
2014-01-13 11:24 1511http://download.csdn.net/downlo ... -
xml转义字符
2013-12-18 09:29 1561" " ' & ... -
字体背景颜色的高度修改
2013-12-11 10:31 4149当使用android:lineSpacingExtra= ... -
屏保的实现
2013-12-07 10:27 2731最近需要做一个屏保,开始以为很简单,因为系统本身就带了屏保功 ... -
PreferenceActivity下嵌套PreferenceScreen在其它布局中
2013-11-21 16:32 9103今天在修改系统代码的时候,系统代码用了PreferenceA ...
相关推荐
此文件为Eclipse下的android工程,里面介绍了listView的三种适配方式,从实现到优化。
现在也加入了DataBinding用的BaseAdapter。 Related posts: 相关博文: ViewGroup 篇 封装博文 DataBinding 篇 封装博文 If you like, point a star .Thank you very much! 喜欢随手点个star 多谢 The ultimate
Android ListView填充数据的方法 因为多人开发,为了是自己开发的...为了给ListView提供数据,我们需要为其设置一个适配,我们可以从BaseAdapter继承,然后重写它的getView方法,这个方法中有一个参数convertView,我们
在Android中通过ListView显示SD卡中的文件列表一共有两种方法,一是:通过继承ListActivity显示;二是:利用BaseAdapter显示。BaseAdapter是一个公共基类适配器,用于对ListView和Spinner等 一些控件提供显示数据。...
一个物联网(IoT)开发的入门教程。涉及单片机、上位机、移动应用、服务器后台开发的知识。...- 3.5 ListView与BaseAdapter - 3.6 Service学习 - 3.7 Android权限机制 - 3.8 BroadCastReciever学习 第
listview中有一些简单使用的适配器,如:SimpleAdapter:构造方法SimpleAdapter(Context context,List<Map> data,reString [] from,int [] to),但这种适配器过于单调,往往不能达到用户想要的效果,想要随心所欲,就...
4:布局方面的当然是最常用的ReleativeLayout,LinearLayout,FrameLayout,include,merge的应用 5:Menu菜单的使用 6:弹出菜单的使用,简单的弹出框,包含list的弹出框. 7:webview嵌入腾讯第三方授权页面的使用 8:最...
8.5 将网络图像网址放入Gallery中显示——URL.URLConnection.BaseAdapter 8.6 即时访问网络图文件展示——HttpURLConnection 8.7 手机气象局,实时卫星云图——HttpURLConnection与URLConnection和运行线程 8.8 通过...
8.5 将网络图像网址放入Gallery中显示——URL.URLConnection.BaseAdapter 8.6 即时访问网络图文件展示——HttpURLConnection 8.7 手机气象局,实时卫星云图——HttpURLConnection与URLConnection和运行线程 8.8 通过...
8.5 将网络图像网址放入Gallery中显示——URL.URLConnection.BaseAdapter 8.6 即时访问网络图文件展示——HttpURLConnection 8.7 手机气象局,实时卫星云图——HttpURLConnection与URLConnection和运行线程 8.8 通过...
8.5 将网络图像网址放入Gallery中显示——URL.URLConnection.BaseAdapter 8.6 即时访问网络图文件展示——HttpURLConnection 8.7 手机气象局,实时卫星云图——HttpURLConnection与URLConnection和运行线程 8.8 ...
8.5 将网络图像网址放入Gallery中显示——URL.URLConnection.BaseAdapter 8.6 即时访问网络图文件展示——HttpURLConnection 8.7 手机气象局,实时卫星云图——HttpURLConnection与URLConnection和运行线程 8.8 通过...
4.18 动态文字排版——GridView与ArrayAdapter设计 4.19 在Activity里显示列表列表——ListView的布局 4.20 以动态列表配置选项——ListActivity与Menu整合技巧 4.21 查找程序根目录下所有文件——JavaI/O与...
8.5 将网络图像网址放入Gallery中显示——URL.URLConnection.BaseAdapter 8.6 即时访问网络图文件展示——HttpURLConnection 8.7 手机气象局,实时卫星云图——HttpURLConnection与URLConnection和运行线程 8.8 通过...
8.5 将网络图像网址放入Gallery中显示——URL.URLConnection.BaseAdapter 8.6 即时访问网络图文件展示——HttpURLConnection 8.7 手机气象局,实时卫星云图——HttpURLConnection与URLConnection和运行线程 8.8 通过...
8.5 将网络图像网址放入Gallery中显示——URL.URLConnection.BaseAdapter 8.6 即时访问网络图文件展示——HttpURLConnection 8.7 手机气象局,实时卫星云图——HttpURLConnection与URLConnection和运行线程 8.8 通过...
8.5 将网络图像网址放入Gallery中显示——URL.URLConnection.BaseAdapter 8.6 即时访问网络图文件展示——HttpURLConnection 8.7 手机气象局,实时卫星云图——HttpURLConnection与URLConnection和运行线程 8.8 通过...