首页 文章 精选 留言 我的

精选列表

搜索[Spring项目],共10000篇文章
优秀的个人博客,低调大师

基于Java的机器学习项目、环境、库...

你是一名希望开始或者正在学习机器学习的Java程序员吗? 利用机器学习编写程序是最佳的学习方式。你可以从头开始编写算法,但是利用现有的开源库,你可以取得更大的进步。 本文介绍了主要的平台和开放源码的机器学习库。你可以使用这些机器学习库。 环境 本节描述了用于机器学习的Java环境或工作域。它们提供了用于执行机器学习任务的图形用户界面,还提供了用于开发自己应用程序的Java API。 WEKA 怀卡托环境知识分析(Weka)( https:// www.cs.waikato.ac.nz/ml/weka/)是一个由新西兰怀卡托大学开发的机器学习平台。提供Java的图形用户接口,命令行接口和Java API接口。它可能是最流行的Java机器学习库,也是开始或练习机器学习的好地方。 KNIME 康斯坦茨信息挖掘(KNIME)(https://www.kn

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

Android 分享机顶盒项目的封装类《GridView》

由于使用系统自带的GridView 不够灵活,不能允许拖拉控件,故自己结合LinearLayout 封装的一个GridView ,通过本篇文章的阅读你可以学会如何自定义控件,如何使用组合控件,如何为自己的组合控件添加数据源和如何为自定义控件添加属性。 首先,我们要实现的效果是这样的: 上面1 2也是一个封装控件,用来为应用程序分页,具体如何实现下篇文章会提到,本篇先讲GridView。如图,这是一个标准的800*480大小的屏幕,所以设置了一页GridView 显示的应用程序数据为 三行五列,不足五列则按需显示。 按照上面的图例需求,大致上可以把GridView 画成如下的方式: 思路如下: 默认将我们的组合控件设置为Orientation是VERTICAL。 首先一行五个,那么一行以一个Orientation 为HORIZONTAL 的线性布局包起来。然后在一行结束后,将Orientation 的线性布局添加进组合控件里面来,不足五个则按需添加进来。 实现这一效果我们需要两个类,一个类用来表示GridView 的行,这里我们起名为TableRow,代码如下: public class TableRow{ private TableCell[]cell; public TableRow(TableCell[]cell){ this .cell = cell; } public int getSize(){ return cell.length; } public TableCellgetCellValue( int index){ if (index >= getSize()){ return null ; } return cell[index]; } public int getCellCount(){ return cell.length; } public int getLastCellCount(){ return lastRowCount; } } 另外一个类用来表示GridView 每行的列个,这里我们取名为TableCell,代码如下: static public class TableCell{ private Objectvalue; public TableCell(Objectvalue){ this .value = value; } public ObjectgetValue(){ return value; } } 并且我们还需要为GridView 设置一个外部可添加数据的方法,代码如下: public void setAdapter(AppsAdapterappsAdapter){ this .adapter = appsAdapter; this .setOrientation(LinearLayout.VERTICAL); bindView(); } 其中,AppsAdapter 是一个自定义的BaseAdapter ,代码很简单,这里就不列出来了。关键的还是要看bindView ,这个方法是本篇GridView 显示数据的核心方法,代码如下: void bindView(){ removeAllViews(); int count = adapter.getCount(); TableCell[]cell = null ; int j = 0 ; LinearLayoutlayout; tableRowsList = new ArrayList < HashMap < String,Object >> (); for ( int i = 0 ;i < count;i ++ ){ j ++ ; final int position = i; if (j > getColumnCount() || i == 0 ){ cell = new TableCell[getColumnCount()]; } finalViewview = adapter.getView(i, null , null ); view.setOnTouchListener( new OnTouchListener(){ @Override public booleanonTouch(Viewv,MotionEvent event ){ // TODOAuto-generatedmethodstub unCheckPressed(); checkRowID = - 1 ; checkColumnID = - 1 ; if (onItemClickEvent != null ){ onItemClickEvent.onItemClick(position, event ,view); } return false ; } }); view.setOnLongClickListener( new OnLongClickListener(){ @Override public booleanonLongClick(Viewv){ if (onLongPress != null ){ onLongPress.onLongPress(v); } return true ; } }); cell[j - 1 ] = new TableCell(view); if (j == getColumnCount()){ lastRowCount = j; j = 0 ; HashMap < String,Object > map = new HashMap < String,Object > (); TableRowtr = new TableRow(cell); map.put( " tableRow " ,tr); tableRowsList.add(map); layout = new LinearLayout(getContext()); addLayout(layout,cell,tr.getSize(),tr); } else if (i >= count - 1 && j > 0 ){ lastRowCount = j; HashMap < String,Object > map = new HashMap < String,Object > (); TableRowtr = new TableRow(cell); map.put( " tableRow " ,tr); tableRowsList.add(map); layout = new LinearLayout(getContext()); addLayout(layout,cell,j,tr); } } } getColumnCount()是一个属性,表示可以从xml或者从代码动态改变GridView 每列显示的个数,属性点的代码为如下: public gridViewExt(Contextcontext,AttributeSetattrs){ super(context,attrs); int resouceID = - 1 ; TypedArraytypedArray = context.obtainStyledAttributes(attrs, R.styleable.GridViewExt); int N = typedArray.getIndexCount(); for ( int i = 0 ;i < N;i ++ ){ int attr = typedArray.getIndex(i); switch (attr){ case R.styleable.GridViewExt_ColumnCount: resouceID = typedArray.getInt( R.styleable.GridViewExt_ColumnCount, 0 ); setColumnCount(resouceID); break ; } } typedArray.recycle(); } 当然,你必须在res 创建属性xml ,这里不多讲,可以去我博客看看如何为View 添加属性。 还有,还必须实现它的支持键盘的上下左右的焦点,下面的代码将会提供该功能,但还必须配合Activity 的操作,等下文再讲述。效果是这样的: 该 类的全部源码为: GridViewExt packagecom.yaomei.widget; importjava.util.ArrayList; importjava.util.HashMap; importjava.util.List; importandroid.content.Context; importandroid.content.Intent; importandroid.content.res.TypedArray; importandroid.util.AttributeSet; importandroid.view.Gravity; importandroid.view.MotionEvent; importandroid.view.View; importandroid.view.ViewGroup; importandroid.widget.LinearLayout; importandroid.widget.TextView; importcom.yaomei.activity.adapter.AppsAdapter; importcom.yaomei.activity.info.R; public class gridViewExtextendsLinearLayout{ public List < HashMap < String,Object >> tableRowsList; private List < HashMap < String,Object >> app = new ArrayList < HashMap < String,Object >> (); private AppsAdapteradapter; onItemClickListeneronItemClickEvent; onLongPressExtonLongPress; int checkRowID = - 1 ; // 选中行的下标 int checkColumnID = - 1 ; // 选中列的下标 int lastRowCount = - 1 ; // 最后一行的总数 private int ColumnCount; // 每列的总数 public void setColumnCount( int count){ this .ColumnCount = count; } public int getColumnCount(){ return ColumnCount; } public interface onItemClickListener{ public booleanonItemClick( int position,MotionEvent event ,Viewview); } public interface onLongPressExt{ public booleanonLongPress(Viewview); } public gridViewExt(Contextcontext){ this (context, null ); // TODOAuto-generatedconstructorstub } public gridViewExt(Contextcontext,AttributeSetattrs){ super(context,attrs); int resouceID = - 1 ; TypedArraytypedArray = context.obtainStyledAttributes(attrs, R.styleable.GridViewExt); int N = typedArray.getIndexCount(); for ( int i = 0 ;i < N;i ++ ){ int attr = typedArray.getIndex(i); switch (attr){ case R.styleable.GridViewExt_ColumnCount: resouceID = typedArray.getInt( R.styleable.GridViewExt_ColumnCount, 0 ); setColumnCount(resouceID); break ; } } typedArray.recycle(); } public void setOnItemClickListener(onItemClickListenerclick){ this .onItemClickEvent = click; } public void setOnLongPressListener(onLongPressExtlongPress){ this .onLongPress = longPress; } public void NotifyDataChange(){ removeAllViews(); } void bindView(){ removeAllViews(); int count = adapter.getCount(); TableCell[]cell = null ; int j = 0 ; LinearLayoutlayout; tableRowsList = new ArrayList < HashMap < String,Object >> (); for ( int i = 0 ;i < count;i ++ ){ j ++ ; final int position = i; if (j > getColumnCount() || i == 0 ){ cell = new TableCell[getColumnCount()]; } finalViewview = adapter.getView(i, null , null ); view.setOnTouchListener( new OnTouchListener(){ @Override public booleanonTouch(Viewv,MotionEvent event ){ // TODOAuto-generatedmethodstub unCheckPressed(); checkRowID = - 1 ; checkColumnID = - 1 ; if (onItemClickEvent != null ){ onItemClickEvent.onItemClick(position, event ,view); } return false ; } }); view.setOnLongClickListener( new OnLongClickListener(){ @Override public booleanonLongClick(Viewv){ if (onLongPress != null ){ onLongPress.onLongPress(v); } return true ; } }); cell[j - 1 ] = new TableCell(view); if (j == getColumnCount()){ lastRowCount = j; j = 0 ; HashMap < String,Object > map = new HashMap < String,Object > (); TableRowtr = new TableRow(cell); map.put( " tableRow " ,tr); tableRowsList.add(map); layout = new LinearLayout(getContext()); addLayout(layout,cell,tr.getSize(),tr); } else if (i >= count - 1 && j > 0 ){ lastRowCount = j; HashMap < String,Object > map = new HashMap < String,Object > (); TableRowtr = new TableRow(cell); map.put( " tableRow " ,tr); tableRowsList.add(map); layout = new LinearLayout(getContext()); addLayout(layout,cell,j,tr); } } } private void addLayout(LinearLayoutlayout,TableCell[]cell, int size, TableRowtr){ LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( 130 , 110 ); layout.setGravity(Gravity.LEFT); layout.setOrientation(LinearLayout.HORIZONTAL); for ( int k = 0 ;k < size;k ++ ){ ViewremoteView = (View)tr.getCellValue(k).getValue(); layout.addView(remoteView,k, params ); } LinearLayout.LayoutParamsfirstParams = new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); firstParams.leftMargin = 60 ; addView(layout,firstParams); } public void setAdapter(AppsAdapterappsAdapter){ this .adapter = appsAdapter; this .setOrientation(LinearLayout.VERTICAL); bindView(); } public void checkPressed( int tableRowId, int tableRowColumnId){ ViewGroupview = (ViewGroup) this .getChildAt(tableRowId); checkColumnID = tableRowColumnId; checkRowID = tableRowId; changeImageState(view.getChildAt(tableRowColumnId),app); } public void onClick( int tableRowId, int tableRowColumnId,Contextcontext){ LinearLayoutview = (LinearLayout)((ViewGroup) this .getChildAt(tableRowId)).getChildAt(tableRowColumnId); TextViewtv = (TextView)view.findViewById(R.id.folder); finalString[]name = tv.getText().toString().split( " - " ); Intentintent = null ; if (name[ 0 ].toString().equals( " com.android.contacts " )){ if (name[ 1 ].toString().equals( " com.android.contacts.DialtactsActivity " )){ intent = new Intent(Intent.ACTION_DIAL); } if (name[ 1 ].toString().equals( " com.android.contacts.DialtactsContactsEntryActivity " )){ intent = new Intent(Intent.ACTION_CALL_BUTTON); } } else { intent = getContext().getPackageManager() .getLaunchIntentForPackage(name[ 0 ].toString()); } context.startActivity(intent); } /* * *改变图片状态 * *@paramv *@paramlist */ private void changeImageState(Viewv,List < HashMap < String,Object >> list){ int size = list.size(); for ( int i = 0 ;i < size;i ++ ){ Viewview = (View)list. get (i). get ( " touch " ); view.setPressed( false ); list.remove(i); } v.setPressed( true ); HashMap < String,Object > map = new HashMap < String,Object > (); map.put( " touch " ,v); list.add(map); } public void unCheckPressed(){ if (checkColumnID != - 1 && checkRowID != - 1 ){ ViewGroupview = (ViewGroup) this .getChildAt(checkRowID); view.getChildAt(checkColumnID).setPressed( false ); } } public class TableRow{ private TableCell[]cell; public TableRow(TableCell[]cell){ this .cell = cell; } public int getSize(){ return cell.length; } public TableCellgetCellValue( int index){ if (index >= getSize()){ return null ; } return cell[index]; } public int getCellCount(){ return cell.length; } public int getLastCellCount(){ return lastRowCount; } } static public class TableCell{ private Objectvalue; public TableCell(Objectvalue){ this .value = value; } public ObjectgetValue(){ return value; } } } 每行显示的LAYOUT文件: < LinearLayout android:orientation ="vertical" android:background ="@drawable/lessbtn" android:gravity ="center" android:layout_width ="fill_parent" android:id ="@+id/grid_layout" android:layout_height ="fill_parent" xmlns:android ="http://schemas.android.com/apk/res/android" > < ImageView android:id ="@+id/btn_appicon" android:layout_width ="55dip" android:layout_height ="55dip" ></ ImageView > < TextView android:id ="@+id/tv_name" android:layout_width ="wrap_content" android:textColor ="#030303" android:layout_height ="wrap_content" ></ TextView > < TextView android:id ="@+id/folder" android:layout_width ="wrap_content" android:visibility ="invisible" android:layout_height ="wrap_content" ></ TextView > </ LinearLayout > 完成这一系列的编写后,你就可以在xml直接写或者在JAVA文件里面new 出来,但注意要设置它每列显示的个数。 下篇将讲述如何实现手势切屏,如何实现分页显示数据,如何实现封装分页控件。 本文转自 terry_龙 51CTO博客,原文链接:http://blog.51cto.com/terryblog/481005,如需转载请自行联系原作者

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

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文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册
修改密码
忘记密码