首页 文章 精选 留言 我的

精选列表

搜索[网站开发],共10000篇文章
优秀的个人博客,低调大师

Android开发之自定义万能BaseAdapter

话不多说哦,直接上模板: package com.zyzpp.adapter; import android.content.Context; import android.util.SparseArray; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; import java.util.ArrayList; public abstract class MyAdapter<T> extends BaseAdapter { private ArrayList<T> mData; private int mLayoutRes; //布局id public MyAdapter() { } public MyAdapter(ArrayList<T> mData, int mLayoutRes) { this.mData = mData; this.mLayoutRes = mLayoutRes; } @Override public int getCount() { return mData != null ? mData.size() : 0; } @Override public T getItem(int position) { return mData.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = ViewHolder.bind(parent.getContext(), convertView, parent, mLayoutRes , position); bindView(holder, getItem(position)); return holder.getItemView(); } public abstract void bindView(ViewHolder holder, T obj); //添加一个元素 public void add(T data) { if (mData == null) { mData = new ArrayList<>(); } mData.add(data); notifyDataSetChanged(); } //往特定位置,添加一个元素 public void add(int position, T data) { if (mData == null) { mData = new ArrayList<>(); } mData.add(position, data); notifyDataSetChanged(); } public void remove(T data) { if (mData != null) { mData.remove(data); } notifyDataSetChanged(); } public void remove(int position) { if (mData != null) { mData.remove(position); } notifyDataSetChanged(); } public void clear() { if (mData != null) { mData.clear(); } notifyDataSetChanged(); } public static class ViewHolder { private SparseArray<View> mViews; //存储ListView 的 item中的View private View item; //存放convertView private int position; //游标 private Context context; //Context上下文 //构造方法,完成相关初始化 private ViewHolder(Context context, ViewGroup parent, int layoutRes) { mViews = new SparseArray<>(); this.context = context; View convertView = LayoutInflater.from(context).inflate(layoutRes, parent, false); convertView.setTag(this); item = convertView; } //绑定ViewHolder与item public static ViewHolder bind(Context context, View convertView, ViewGroup parent, int layoutRes, int position) { ViewHolder holder; if (convertView == null) { holder = new ViewHolder(context, parent, layoutRes); } else { holder = (ViewHolder) convertView.getTag(); holder.item = convertView; } holder.position = position; return holder; } @SuppressWarnings("unchecked") public <T extends View> T getView(int id) { T t = (T) mViews.get(id); if (t == null) { t = (T) item.findViewById(id); mViews.put(id, t); } return t; } /** * 获取当前条目 */ public View getItemView() { return item; } /** * 获取条目位置 */ public int getItemPosition() { return position; } /** * 设置文字 */ public ViewHolder setText(int id, CharSequence text) { View view = getView(id); if (view instanceof TextView) { ((TextView) view).setText(text); } return this; } /** * 设置图片 */ public ViewHolder setImageResource(int id, int drawableRes) { View view = getView(id); if (view instanceof ImageView) { ((ImageView) view).setImageResource(drawableRes); } else { view.setBackgroundResource(drawableRes); } return this; } /** * 设置点击监听 */ public ViewHolder setOnClickListener(int id, View.OnClickListener listener) { getView(id).setOnClickListener(listener); return this; } /** * 设置可见 */ public ViewHolder setVisibility(int id, int visible) { getView(id).setVisibility(visible); return this; } /** * 设置标签 */ public ViewHolder setTag(int id, Object obj) { getView(id).setTag(obj); return this; } /** * 设置文字and颜色 */ public ViewHolder setTextAndColor(int id, CharSequence text,int color) { View view = getView(id); if (view instanceof TextView) { ((TextView) view).setText(text); ((TextView) view).setTextColor(color); } return this; } //其他方法可自行扩展 } } 下面说一下ListView(GridView)的使用流程: private void useListView() { //绑定View listview = (ListView) view.findViewById(R.id.grid_ico); //添加头部View listview.addHeaderView(headview); //添加数据 mData = new ArrayList<>(); mData.add(new ListItem(R.mipmap.dot, "这是自定义JavaBean")); //添加数据源 mAdapter = new MyAdapter<ListItem>(mData, R.layout.item_grid_icon) { @Override public void bindView(ViewHolder holder, ListItem obj) { holder.setImageResource(R.id.img_icon, obj.getId()); holder.setText(R.id.txt_js, obj.getContent()); } }; //把数据源set进视图 listview.setAdapter(mAdapter); //监听点击事件 listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Toast.makeText(getActivity(), "你点击了~" + position + "~项", Toast.LENGTH_SHORT).show(); switch (position) { case 1: break; } } }); //监听长按事件 listview.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Toast.makeText(getActivity(), "你长按了第~" + position + "~项", Toast.LENGTH_SHORT).show(); return true; //默认不处理返回false } }); }

优秀的个人博客,低调大师

iOS开发之将XML转换成树II

前面一篇文章,很好将xml转换成树,并进行操作,但是忽略了对xml节点上属性的操作,现在让我来修改代码,将属性添加进来。 1、在treenode中加一个类型为NSDictionary的attributeDict用于存放属性。代码如下: NSDictionary * attributeDict; 2、在中可以在parser:didStartElement:方法中取到属性列表,在其中添加添加下面代码。 leaf.attributeDict = [[ NSDictionary alloc] initWithDictionary:attributeDict]; 3、修改样例xml。 <? xml version="1.0" encoding="UTF-8"?> < Login > < LoginResult id="1">True</ LoginResult > < LoginInfo >OK</ LoginInfo > < LastLogin >2011-05-09 12:20</ LastLogin > < Right > < A >1</ A > < B >1</ B > < C >0</ C > </ Right > </ Login > 4、取属性id的值。 TreeNode * resultTreeNode = [node objectForKey:@ "LoginResult" ]; NSString *result = [resultTreeNode.attributeDict objectForKey:@ "id" ]; 本文转自麒麟博客园博客,原文链接:http://www.cnblogs.com/zhuqil/archive/2011/07/27/2117904.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

使用Spring Boot来加速Java web项目的开发

我想,现在企业级的Java web项目应该或多或少都会使用到Spring框架的。 回首我们以前使用Spring框架的时候,我们需要首先在(如果你使用Maven的话)pom文件中增加对相关的的依赖(使用gradle来构建的话基本也一样)然后新建Spring相关的xml文件,而且往往那些xml文件还不会少。然后继续使用tomcat或者jetty作为容器来运行这个工程。基本上每次创建一个新的项目都是这么一个流程,而我们有时候仅仅想快速的创建一个Spring web工程来测试一些东西,或者是希望能节省时间。 现在我们使用Spring Boot就可以快速的做到这些了。 我们先来看一个非常简单的使用Spring boot的例子吧: 1. 我们创建一个Maven工程,假定工程名字为spring-boot,然后我们在pom.xml文件中加入依赖: 1 2 3 4 5 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version> 1.0 . 2 .RELEASE</version> </dependency> 2. 新建一个Controller来接受处理我们的请求: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; /** * Created by wenchao.ren on 2014/4/26. */ @Controller @EnableAutoConfiguration public class SimpleController { @RequestMapping (value = "/hello" , method = RequestMethod.GET) @ResponseBody public String hello(){ return "hello world" ; } public static void main(String[] args) { SpringApplication.run(SimpleController. class , args); } } 相信大家已经看到了这个Controller有一个main方法,不要急,我们直接运行这个main方法: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | ' _| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v1. 0.2 .RELEASE) 2014 - 04 - 26 22 : 54 : 40.985 INFO 7236 --- [ main] c.r.spring.boot.SimpleController : Starting SimpleController on rollen with PID 7236 (D:\workspace\GitHub\SpringDemo\spring-boot\target\classes started by wenchao.ren in D:\workspace\GitHub\SpringDemo\spring-boot) 2014 - 04 - 26 22 : 54 : 41.008 INFO 7236 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext @50de0926 : startup date [Sat Apr 26 22 : 54 : 41 CST 2014 ]; root of context hierarchy 2014 - 04 - 26 22 : 54 : 41.583 INFO 7236 --- [ main] .t.TomcatEmbeddedServletContainerFactory : Server initialized with port: 8080 2014 - 04 - 26 22 : 54 : 41.706 INFO 7236 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat 2014 - 04 - 26 22 : 54 : 41.706 INFO 7236 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/ 7.0 . 52 2014 - 04 - 26 22 : 54 : 41.785 INFO 7236 --- [ost-startStop- 1 ] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2014 - 04 - 26 22 : 54 : 41.785 INFO 7236 --- [ost-startStop- 1 ] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 779 ms 2014 - 04 - 26 22 : 54 : 42.055 INFO 7236 --- [ost-startStop- 1 ] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/] 2014 - 04 - 26 22 : 54 : 42.057 INFO 7236 --- [ost-startStop- 1 ] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [ /*] 2014-04-26 22:54:42.289 INFO 7236 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/ favicon.ico] onto handler of type [ class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2014 - 04 - 26 22 : 54 : 42.368 INFO 7236 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/hello],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.rollenholt.spring.boot.SimpleController.hello() 2014 - 04 - 26 22 : 54 : 42.376 INFO 7236 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [ class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2014 - 04 - 26 22 : 54 : 42.377 INFO 7236 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [ class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2014 - 04 - 26 22 : 54 : 42.447 INFO 7236 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 2014 - 04 - 26 22 : 54 : 42.459 INFO 7236 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 /http 2014 - 04 - 26 22 : 54 : 42.460 INFO 7236 --- [ main] c.r.spring.boot.SimpleController : Started SimpleController in 1.675 seconds (JVM running for 1.944 ) 2014 - 04 - 26 22 : 54 : 54.963 INFO 7236 --- [nio- 8080 -exec- 1 ] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet' 2014 - 04 - 26 22 : 54 : 54.963 INFO 7236 --- [nio- 8080 -exec- 1 ] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet' : initialization started 2014 - 04 - 26 22 : 54 : 54.971 INFO 7236 --- [nio- 8080 -exec- 1 ] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet' : initialization completed in 8 ms 会产生上面的输出,查看日志可以发现默认使用的是tomcat,端口绑定在8080,现在让我们来访问:http://localhost:8080/hello 就可以看到我们代码中输出的字样:hello world了。 回首这个过程,是不是相比于以前快速了许多呢 参考资料: 1. Spring Boot Reference Guide ============================================================================== 本文转自被遗忘的博客园博客,原文链接:http://www.cnblogs.com/rollenholt/p/3693055.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

iOS开发之在google地图上显示自己的位置

一行代码显示你的位置 iOS中的MapKit集成了定位的功能,使用一行代码就可以在google地图上展示出自己当前的位置,代码如下: -( IBAction ) showLocation:( id ) sender { if ([[btnShowLocation titleForState:UIControlStateNormal] isEqualToString:@ "Show My Location" ]) { [btnShowLocation setTitle:@ "Hide My Location" forState:UIControlStateNormal]; mapView.showsUserLocation = YES ; } else { [btnShowLocation setTitle:@ "Show My Location" forState:UIControlStateNormal]; mapView.showsUserLocation = NO ; } } 关键的代码就是:mapView.showUserLocation=YES. 使用CLLocationManager和MKMapView 还有就是通过CoreLocation框架写代码去请求当前的位置,一样也非常简单: 第一步:创建一个CLLocationManager实例 CLLocationManager *locationManager = [[CLLocationManager alloc] init]; 第二步:设置CLLocationManager实例委托和精度 locationManager.delegate = self ; locationManager.desiredAccuracy = kCLLocationAccuracyBest; 第三步:设置距离筛选器distanceFilter,下面表示设备至少移动1000米,才通知委托更新 locationManager.distanceFilter = 1000.0f; 或者没有筛选器的默认设置: locationManager.distanceFilter = kCLDistanceFilterNone; 第四步:启动请求 [locationManager startUpdatingLocation]; 使用下面代码停止请求: [locationManager stopUpdatingLocation]; CLLocationManagerDelegate委托 这个委托中有:locationManager:didUpdateToLocation:fromLocation方法,用于获取经纬度。 可以使用下面代码从CLLocation 实例中获取经纬度 CLLocationDegrees latitude = theLocation.coordinate.latitude; CLLocationDegrees longitude = theLocation.coordinate.longitude; 使用下面代码获取你的海拔: CLLocationDistance altitude = theLocation.altitude; 使用下面代码获取你的位移: CLLocationDistance distance = [fromLocation distanceFromLocation:toLocation]; 总结:本文主要是讲解了如何在iOS设备google地图上展示自己的当前位置。 本文转自麒麟博客园博客,原文链接:http://www.cnblogs.com/zhuqil/archive/2011/07/13/2105013.html,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册