1、使用xmlPull解析xml数据得不到数据?但是解析方法是正确的
首先检查自己的解析方法是否正确,如果没错的重点查找xml数据的“格式”是否正确!!
比如上图,大家能看出传递过来的xml数据哪里不对。其实是这里<!--姓名 ->注释的格式不对,正确的应该是<!--姓名 -->,大家可以比较下看,后者比前者多了一个横线。如果数据格式是前者,即使解析方法正确,也得不到正确的值。
虽然这种机会很少碰到,但是今天就遇到了,刚开始还以为自己的解析方法不对,查找了一个下午才找到。
同时,如果解析的是字符串。可以用ByteArrayInputStream(str.getBytes)转为一个InputStream。
2、SVN提交错误:working copy is not up-to-date解决方法
svn在提交时报错如下图:
working copy is not up-to-date
svn:commit failed(details follow):
svn:file "xxxxx is out of date"
item is out of date
svn:item "xxxx" is out of date
解决方法:
在相应文件上,单击选择team,然后选择先更新,然后再提交。这样就好了
3、
android Spinner默认不选中项目开发中经常有些变态的需求,比如要求spinner默认不选中任何一项。
如果你自定义spinner,那这个当然不是问题;也可以在原有的选项列表中开头增加一项空字符串项,默认显示这个空字符串也达到了效果,不过采用这种方式需要你在获取被选择项的位置时忽略空字符串项。
经过一番摸索,发现我们只要保证 spinner第一次展示时不显示即可,相关代码如下:
boolean isSpinnerFirst = true ; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main) ; Spinner spinner = (Spinner)findViewById(R.id.spinner) ; spinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (isSpinnerFirst) { //第一次初始化spinner时,不显示默认被选择的第一项即可 view.setVisibility(View.INVISIBLE) ; } isSpinnerFirst = false ; } @Override public void onNothingSelected(AdapterView parent) { } }) ; }
4、安卓文本中一些特殊的文本输入,需要使用ASCII码
http://blog.csdn.net/z1074971432/article/details/12753539
5、文本颜色的字体选择器,注意不是用drawable了,而是使用color,(虽然drawable可以用颜色表示)
下面这个是字体颜色的选择器
- <?xml version="1.0" encoding="utf-8"?>
- <selector xmlns:android="http://schemas.android.com/apk/res/android" >
- <!-- index首页底部选择字体的 颜色选择器 -->
- <item android:state_selected="true" android:color="@color/font_blue_color"></item>
- <item android:color="@color/font_black_color"></item>
- </selector>
下面这个是按钮的背景选择器
- <selector xmlns:android="http://schemas.android.com/apk/res/android" >
- <item android:drawable="@color/btn_rigth_pressed" android:state_pressed="true"></item>
- <item android:drawable="@color/btn_right_normal"></item>
- </selector>
6、
今天无意中碰见了 case expressions must be constant expressions 的问题
写了一个
- switch (v.getId()) {
- case R.id.ivTitleBtnRightImage:
- LuTaiService xxService = mFragmentCallBack.getService();
- if (xxService == null || !xxService.isAuthenticated()) {
- return;
- }
- new AddRosterItemDialog(mFragmentCallBack.getMainActivity(),
- xxService).show();// 添加联系人
- break;
- default:
- break;
- }
导入到其它的工程里面 case R.id.ivTitleBtnRightImage : 出现了错误
错误提示为:case expressions must be constant expressions
网上查了一下 发现是 我的工程 勾选了isLibrary 的原因,将 勾选 去掉 再clear一下 就好
7、调用webService出现
Unexpected token (position:TEXT
05-15 15:52:15.901: I/System.
out
(1429):
------=_Part_0_...@5:13 in java.io.InputStreamReder
正常情况下,android使用google的ksoap2这个包,就可以正常调用webService,前提条件是,服务端回传的必须是xml数据。
出现这个异常,原因是服务端回传的不是xml数据,而是如下图所示
可以看到,回传的数据不是传统的xml数据,当ksoap2解析服务端数据,发现不是xml数据就报错了
这个时候,就不能用ksoa2去调用webService了,必须使用传统的http协议,发送post请求,代码如下
8、TabHost,添加TabWidget时,默认是有分割线的,可以在进行控制。
- <TabWidget
- android:id="@android:id/tabs"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:showDividers="none"//这样tabwidget内tab间的分割线就没有了,就可以做viewpager的指示器了(内容是个imageview),显示到viewpager的哪一个item
- android:divider="#ff00ff" //这样tabwidget内tab间就又分割线了,而且分割线的颜色为#ff00ff
- >
- </TabWidget>
9、出现java.net.SocketException: socket failed: EACCES (Permission denied)
是没有添加权限,到主配置文件加上相应权限即可
10、fragmentTabHost之间 用bundle传值
- // host.addTab(选项卡,内容,参数Bundle);
- host.addTab(tab, fragments[i], bundle);
11、ViewUtil.inject()要放在setContenView()之下,否则出现空指针异常
12、一个float 保留2位小数,转成字符串
- float result=(float) Math.random() * 30 + 15;
- g.format("%.2f", result); //保留2为小数
13、PullToRefresh
在初始化完成PullToRefreshListView后,通过lv.getLoadingLayoutProxy()可得到一个ILoadingLayout对象,这个对象可设置各种指示器中的样式、文本等。
- ILoadingLayout startLabels = mPullRefreshListView
- .getLoadingLayoutProxy();
- startLabels.setPullLabel("你可劲拉,拉...");// 刚下拉时,显示的提示
- startLabels.setRefreshingLabel("好嘞,正在刷新...");// 刷新时
- startLabels.setReleaseLabel("你敢放,我就敢刷新...");// 下来达到一定距离时,显示的提示
- private void initIndicator(){
- ILoadingLayout startLabels = mPullRefreshListView
- .getLoadingLayoutProxy(true, false);
- startLabels.setPullLabel("你可劲拉,拉...");// 刚下拉时,显示的提示
- startLabels.setRefreshingLabel("好嘞,正在刷新...");// 刷新时
- startLabels.setReleaseLabel("你敢放,我就敢刷新...");// 下来达到一定距离时,显示的提示
- ILoadingLayout endLabels = mPullRefreshListView.getLoadingLayoutProxy(
- false, true);
- endLabels.setPullLabel("你可劲拉,拉2...");// 刚下拉时,显示的提示
- endLabels.setRefreshingLabel("好嘞,正在刷新2...");// 刷新时
- endLabels.setReleaseLabel("你敢放,我就敢刷新2...");// 下来达到一定距离时,显示的提示
http://blog.csdn.net/ueryueryuery/article/details/17440465
https://github.com/chrisbanes/Android-PullToRefresh/wiki/Quick-Start-Guide
http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2014/1215/2166.html
补充,这个控件有headView,所以索引是从1开始的,0为head
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
doSomething(parent.getAdapter().getItem(position));
}
在listView的setOnItemClickListener最后写上面的代码
或者 listData.get(position-1)
否则出现指针越界异常
参考
http://blog.csdn.net/sbvfhp/article/details/44959917
补充:如果这个pullToRefresh想增加setOnLongItemClick方法,请参考下面网址
http://blog.csdn.net/u012721519/article/details/51112560
- public void setOnItemLongClickListener(AdapterView.OnItemLongClickListener listener) {
- mRefreshableView.setOnItemLongClickListener(listener);
- }
14、Android showDialog时报错requestFeature() must be called before adding content
01-08 10:06:54.670: E/AndroidRuntime(1968): android.util.AndroidRuntimeException: requestFeature() must be called before adding content
01-08 10:06:54.670: E/AndroidRuntime(1968): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:192)
01-08 10:06:54.670: E/AndroidRuntime(1968): at com.android.internal.app.AlertController.installContent(AlertController.java:234)
01-08 10:06:54.670: E/AndroidRuntime(1968): at android.app.AlertDialog.onCreate(AlertDialog.java:314)
01-08 10:06:54.670: E/AndroidRuntime(1968): at android.app.Dialog.dispatchOnCreate(Dialog.java:335)
01-08 10:06:54.670: E/AndroidRuntime(1968): at android.app.Dialog.show(Dialog.java:248)
01-08 10:06:54.670: E/AndroidRuntime(1968): at com.android.test.showDialog(MainActivity.java:121)
出现此问题是由于dialog.show()之前调用了dialog.setContentView()或者dialog.getwindow()等,正确的应该是dialog.show()之后调用dialog.setContentView()
参考
http://blog.csdn.net/lzt623459815/article/details/8479745
15、xutil的一些参考文档
http://www.tuicool.com/articles/MVNzUnI
Xutils3的使用
http://www.w2bc.com/Article/84851
xutil的多文件上传填写
- HttpUtils http = new HttpUtils(10000);
- RequestParams params = new RequestParams();
- //设置文件
- MultipartEntity entity = new MultipartEntity();
- for (int i = 0; i < fileList.size();i++) {
- entity.addPart("file" + i,new FileBody(fileList.get(i)));
- }
- try {
- entity.addPart("creator", new StringBody(create_id_txt));
- entity.addPart("record_id", new StringBody(problem_id_txt));
- } catch (UnsupportedEncodingException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
16、android给listview的item设定高度失败
http://blog.csdn.net/l_serein/article/details/7403992
四种方案解决ScrollView嵌套ListView问题
http://bbs.anzhuo.cn/thread-982250-1-1.html
17、
MultipartEntity与UrlEncodedFormEntity区别
http://www.pm-road.com/index.php/2014/10/16/118/
http://shenyuc629.iteye.com/blog/1876378
19、常用的2个shape 和selector
下面这个是空心有边框的shape
- <?xml version="1.0" encoding="utf-8"?>
- <shape xmlns:android="http://schemas.android.com/apk/res/android" >
- <!-- 实心 -->
- <solid android:color="@android:color/white" />
- <!-- 边框 -->
- <stroke
- android:width="0.5dp"
- android:color="#CBCBCB" />
- <!-- 圆角 -->
- <corners android:radius="3dp" />
- <!-- 边距 -->
- <padding
- android:bottom="1dp"
- android:left="6dp"
- android:right="6dp"
- android:top="1dp" />
- </shape>
下面是一个正常情况透明,点击变色的selector
- <?xml version="1.0" encoding="utf-8"?>
- <selector xmlns:android="http://schemas.android.com/apk/res/android" >
- <item android:state_pressed="true" >
- <shape>
- <solid android:color="@color/btn_green_predss" />
- </shape>
- </item>
- <item android:state_enabled="false" >
- <shape>
- <solid android:color="@android:color/transparent" />
- </shape>
- </item>
- <item>
- <shape>
- <solid android:color="@android:color/transparent" />
- </shape>
- </item>
- </selector>
20、
- //GridView的常用布局
- <GridView
- android:id="@+id/gridView"
- android:layout_below="@id/actionbarLayout"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:numColumns="3"
- android:stretchMode="columnWidth"
- android:listSelector="@android:color/transparent"
- />
- //ListView的常用布局
- <ListView
- android:id="@+id/listview"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:background="@android:color/white"
- android:divider="#EBE7E8"
- android:dividerHeight="1dip"
- android:fadingEdge="none"
- android:fastScrollEnabled="false"
- android:footerDividersEnabled="false"
- android:headerDividersEnabled="false"
- android:smoothScrollbar="true" />
21、在oncreate()中利用view.getWidth()或是view.getHeiht()来获取view的宽和高,看似没有问题,其实他们去得值是0,并不是你想要的结果?
http://www.2cto.com/kf/201312/268110.html
- View itemView=View.inflate(context, R.layout.item_hr_have_publish_position_detail, null);//这个是想要得到的layout布局
- int w = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);
- int h = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);
- itemView.measure(w, h);
- int height =itemView.getMeasuredHeight();//这里得到了布局的高度
//一个得到屏幕高度的工具类
- ScreenUtil.initScreen(ReceiveResumeActivity.this);
- int ScreenH=ScreenUtil.getScreenH();
- if(position==mResult.getTargetJobList().size()-1&&(position+1)*height>ScreenH){
- popWin.showAsDropDown(view, 0, -144); //点击listView中的最后一个item,并且item的总长度大于屏幕高度,popupWindow显示上面
- }else{
- popWin.showAsDropDown(view, 0, 0); //否则,popupWindow显示在item屏幕下方
- }
22、常用的技巧
一、标题栏的隐藏
方法1、
在Activity的oncreate方法中添加requestWindow()方法,需要注意的是它必须放在setsetContentView()方法之前,否则会报错。- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- setContentView(R.layout.main);
- ……}
在配置文件Xml中设置Acitivity的theme属性
- <activity
- android:theme="@android:style/Theme.NoTitleBar"
- android:name=".Test" >
- ……
- </activity>
二、状态栏的隐藏
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- // this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
- setContentView(R.layout.main);
- this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
- ……}
在Activity的oncreate方法中添加requestWindow()方法,在setsetContentView()方法之前之后都可以。
三、全屏的实现
方法1、
在Activity的oncreate方法中设置
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- this.requestWindowFeature(Window.FEATURE_NO_TITLE);
- this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
- setContentView(R.layout.main);
- ……}
在配置文件Xml中设置Acitivity的theme属性
- <activity
- android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
- android:name=".Test" >
- ……
- </activity>
以上三点只针对某一个Acitivity窗口进行设置,若想针对应用程序所有的Activity,那么直接在配置文件里进行设置,如
- <application
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name"
- android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
23、unable to find attribute android:preserveIconSpacing 这个错误如何解决?
http://www.imooc.com/qadetail/89022
点击V7包找到values文件夹 ,打开attrs.xml , ctrl+f 查找 MenuView , 将preserveIconSpacing注释掉或者删掉 , clean项目
24、Android PullToRefresh (ListView GridView 下拉刷新) 使用详解
http://blog.csdn.net/ljx19900116/article/details/41649195
25、Google自己的下拉刷新组件SwipeRefreshLayout
谷歌官方的swiperefreshlayout圆圈式下拉刷新,因为加了两个新的v4和v7兼容包,所以才有圆圈的效果,如果没有新的v4和v7兼容包,就是旧的彩线的效果.这里仅提供新的圆圈式效果。
如果想用圆圈的样式,需要去Android sdk manager里把Android support library升级到最新23版,如果是19版样式仍然是横线
26 SwipeMenuListView 需要引入一个外部库,代码
- // step 1. 设置item 目录
- SwipeMenuCreator creator = new SwipeMenuCreator() {
- @Override
- public void create(SwipeMenu menu) {
- //设置目录的选项
- SwipeMenuItem deleteItem = new SwipeMenuItem(context);
- // 设置目录背景 ,这里设置为红色
- deleteItem.setBackground(new ColorDrawable(Color.rgb(0xF9,
- 0x3F, 0x25)));
- // 设置背景宽度
- deleteItem.setWidth(DensityUtil.dip2px(context, 90));
- // 设置背景图片
- deleteItem.setIcon(R.drawable.ic_delete);
- //添加都目录里
- menu.addMenuItem(deleteItem);
- }
- };
- //listView要添加目录
- lvPosition.setMenuCreator(creator);
- // step 2. 设置目录监听器
- lvPosition.setOnMenuItemClickListener(new OnMenuItemClickListener() {
- @Override
- //目录的index ,表示目录item的数量,从0开始
- //position 表示listView item的数量
- public void onMenuItemClick(int position, SwipeMenu menu, int index) {
- Position entity = positionList.get(position);
- switch (index) {
- case 0:
- // 取消收藏
- cancleCollect(entity.getPositionId());
- positionList.remove(entity);
- adapter.notifyDataSetChanged();
- break;
- }
- }
- });
27、点击查看大图代码 ,见youzi 的PositionDetailActivity
- //点击查看大图
- private URL url=null;
- private Bitmap bitmap = null;
- private AlertDialog alertdialog ;
- private ImageView imgView;
- private Handler handler=new Handler(){
- public void handleMessage(android.os.Message msg) {
- if(msg.what==1){
- imgView.setImageBitmap(bitmap);
- alertdialog.show();
- alertdialog.setContentView(imgView);
- }
- };
- };
- //--点击查看大图分割线
- private void lookBigPic() {
- if (!TextUtils.isEmpty(detail.getLogo())) {
- // CustomApplication.getBitmapUtils().display(ivLogo, URLConfig.SERVER_HOST_IMAGE + detail.getLogo());
- alertdialog = new AlertDialog.Builder(context).create();
- imgView = new ImageView(context);
- imgView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
- LayoutParams.MATCH_PARENT));
- new Thread(new Runnable() {
- LoadingDialog dialog= PromptUtil.showLoadingDialog(context,null);;
- @Override
- public void run() {
- try {
- url = new URL(URLConfig.SERVER_HOST_IMAGE
- + detail
- .getLogo());
- InputStream is = url.openConnection().getInputStream();
- BufferedInputStream bis = new BufferedInputStream(is);
- bitmap = BitmapFactory.decodeStream(bis);
- bis.close();
- is.close();
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }finally{
- PromptUtil.closeLoadingDialog(dialog);
- Message message=new Message();
- message.what=1;
- handler.sendMessage(message);
- }
- }
- }).start();
- }
- }
28、
现在有一种需求,一个按钮的背景要显示3种颜色
1、enable模式
2 disables模式
3、点击press模式
4、不可press模式就是enable模式,默认都是为true
多用在短信验证码的按钮上
- <?xml version="1.0" encoding="utf-8"?>
- <selector xmlns:android="http://schemas.android.com/apk/res/android" >
- <!-- 设置按压 -->
- <item android:state_pressed="true" >
- <shape>
- <solid android:color="@color/btn_rigth_pressed" />
- </shape>
- </item>
- <!-- 是否可以点击 -->
- <item android:state_enabled="true">
- <shape>
- <solid android:color="@color/btn_right_normal" />
- </shape>
- </item>
- <item android:state_enabled="false">
- <shape>
- <solid android:color="#CDCDCD" /> 这里是灰色颜色
- </shape>
- </item>
- </selector>
29、一个会犯错的布局,
如果一个Relative布局里面还有RelativeLayou,这个布局有点击事件,需要在里面的RelativeLayout布局里写clickable=true事件
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="@android:color/white"
- android:orientation="horizontal">
- <RelativeLayout
- android:layout_width="0dp"
- android:layout_weight="1"
- android:layout_height="wrap_content"
- android:layout_marginBottom="7dp"
- android:layout_marginTop="7dp"
- >
- <TextView
- android:id="@+id/tv_name"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="15dp"
- android:text="钱夫人"
- android:textColor="#000000"
- android:textSize="@dimen/main_text_size" />
- <TextView
- android:id="@+id/tv_phone_number"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="15dp"
- android:layout_toRightOf="@+id/tv_name"
- android:text="15989009065"
- android:textColor="#000000"
- android:textSize="@dimen/main_text_size" />
- <TextView
- android:id="@+id/tv_address"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/tv_name"
- android:layout_below="@+id/tv_name"
- android:layout_marginRight="8dp"
- android:layout_marginTop="10dp"
- android:ellipsize="end"
- android:maxLines="2"
- android:text="广州市天河区五山科华街"
- android:textColor="@color/font_gray_color"
- android:textSize="@dimen/sub_text_size" />
- </RelativeLayout>
- <View
- android:id="@+id/view_line"
- android:layout_width="0.6dp"
- android:layout_height="match_parent"
- android:layout_marginBottom="6dp"
- android:layout_marginTop="6dp"
- android:background="@color/line_gray_color" />
- <RelativeLayout
- android:id="@+id/rl_edit_address"
- android:layout_width="40dp"
- android:layout_height="match_parent"
- android:background="@drawable/selector_listview_item"
- android:clickable="true" >
- <ImageView
- android:id="@+id/iv_edit_address"
- android:layout_width="20dp"
- android:layout_height="20dp"
- android:layout_centerInParent="true"
- android:src="@drawable/icon_edit_address" />
- </RelativeLayout>
- </LinearLayout>
30、压缩图片的2个笔记
1个是通过bitmap来压缩,适合通过startAcitivityForResult变形图片后,得到bitmap,上传到后台
1个是通过file来压缩,适合选择图片通过uri得到file上传到后台,要压缩来节省流量
http://www.360doc.com/content/14/0428/17/11800748_372972179.shtmlhttp://104zz.iteye.com/blog/1694762
- /**
- * 通过url得到图片文件
- * @param uri
- * @return
- * @author hemiy
- */
- public File getFileByUri(Uri uri) {
- String path = null;
- if ("file".equals(uri.getScheme())) {
- path = uri.getEncodedPath();
- if (path != null) {
- path = Uri.decode(path);
- ContentResolver cr = context.getContentResolver();
- StringBuffer buff = new StringBuffer();
- buff.append("(").append(Images.ImageColumns.DATA).append("=").append("'" + path + "'").append(")");
- Cursor cur = cr.query(Images.Media.EXTERNAL_CONTENT_URI, new String[] { Images.ImageColumns._ID, Images.ImageColumns.DATA }, buff.toString(), null, null);
- int index = 0;
- int dataIdx = 0;
- for (cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) {
- index = cur.getColumnIndex(Images.ImageColumns._ID);
- index = cur.getInt(index);
- dataIdx = cur.getColumnIndex(Images.ImageColumns.DATA);
- path = cur.getString(dataIdx);
- }
- cur.close();
- if (index == 0) {
- } else {
- Uri u = Uri.parse("content://media/external/images/media/" + index);
- System.out.println("temp uri is :" + u);
- }
- }
- if (path != null) {
- return new File(path);
- }
- } else if ("content".equals(uri.getScheme())) {
- // 4.2.2以后
- String[] proj = { MediaStore.Images.Media.DATA };
- Cursor cursor = context.getContentResolver().query(uri, proj, null, null, null);
- if (cursor.moveToFirst()) {
- int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
- path = cursor.getString(columnIndex);
- }
- cursor.close();
- return new File(path);
- } else {
- Log.i("d", "Uri Scheme:" + uri.getScheme());
- }
- return null;
- }
31、一些android的小知识点
判断服务是否启动
检测屏幕是否开启
http://www.tuicool.com/articles/juqIN3J
http://blog.csdn.net/hustpzb/article/details/8072630
所以,如果ListView的高度是fill_parent,那么当Item很少,而没有能填满ListView的高度的时候,底部就会出现分割线。反之,如果ListView的高度是wrap_content,那么ListView的高度就是随着Item的增多而变高的,最后一行的Item始终是达到了ListView的底部,也就不会出现分割线了。
33、
让ListView实现跟QQ、微信、陌陌那样信息从底部开始
http://blog.csdn.net/minglun1234/article/details/22086875
让自己的聊天界面ListView实现向众多聊天软件那样从底部开始,其实很简单,只需要在实例化的ListView设置setStackFromBottom(true);即可实现刚刚开始的信息是显示在底部的~~
34、一个关于邮箱的正则表达式
/^[a-zA-Z0-9
#_~!$&'()*+,;=:."(),:;<>@\[\]\\]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$/
35、删除文件夹里面所有文件的代码
private void deleteAllFileDir(File file) {
if (file.exists()) {//判断文件是否存在
if (file.isFile()) {//判断是否是文件
file.delete();//删除文件
} else if (file.isDirectory()) {//否则如果它是一个目录
File[] files = file.listFiles();//声明目录下所有的文件 files[];
for (int i = 0;i < files.length;i ++) {//遍历目录下所有的文件
this.deleteAllFileDir(files[i]);//把每个文件用这个方法进行迭代
}
file.delete();//删除文件夹
}
} else {
System.out.println("所删除的文件不存在");
// return;
}
}
36、
android控件EditText的setOnEditorActionListener方法理解
当我们定义一个可编辑控件EditText时
EditText ET_phone = (EditText) findViewById(R.id.ET_phonenumber);
会添加一个方法:
- ET_phone.setOnEditorActionListener(new OnEditorActionListener() {
- @Override
- public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
- Log.e("点击ET_phone", "没有响应");
- text.setText("Editing ET_phonenumber");
- return false;
- }
- });
37、listView中图片加载出现错位的一个解决方案
首先,图片加载错位可以参考文章
http://blog.csdn.net/guolin_blog/article/details/45586553
核心思路是,给图片控件添加一个tag,这个tag是图片的网络地址,当获取的网络图片地址和tag不一样时,才添加新的网络图片
- String profilePhoto=entity.getProfilePhoto();
- if(!TextUtils.isEmpty(profilePhoto)){
- if(!profilePhoto.equals(holder.ivAvatar.getTag())){
- CustomApplication.getBitmapUtils().display(holder.ivAvatar, URLConfig.SERVER_HOST+profilePhoto,DefaultHeader.getDefaultHeader());
- holder.ivAvatar.setTag(profilePhoto);//当出现不一致时,才设置新的图片
- }
- }else{
- holder.ivAvatar.setImageResource(R.drawable.avatar); //没有网络图片,设置为默认的本地图片
- holder.ivAvatar.setTag(null);
- }
38、gridView的一些总结
- <!--这里只用设置列数即可,其他的参数可以不要-->
- GridView
- android:id="@+id/gridView"
- android:gravity="center"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:numColumns="4"
- android:horizontalSpacing="5dp"
- android:verticalSpacing="5dp">
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:gravity="center"
- android:padding="10dp"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
- <!--item的宽度可以设置为任意长度,但是高度可以自定义。-->
- <!--比如图片的宽随便取值,但是高度会具体反映在gridView上-->
- <ImageView
- android:src="@drawable/icon_female_pressed"
- android:id="@+id/image"
- android:layout_width="600dp"
- android:layout_height="50dp"
- />
- <TextView
- android:id="@+id/text"
- android:layout_marginTop="5dp"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textColor="@color/black"
- android:text="文字"
- />
- </LinearLayout>
39、改变toast的字体大小
- Toast toast = Toast.makeText(IndexActivity.this, "这个是一个测试", Toast.LENGTH_SHORT);
- // 修改Toast字体大小
- LinearLayout linearLayout = (LinearLayout) toast.getView();
- TextView messageTextView = (TextView) linearLayout.getChildAt(0);
- messageTextView.setTextSize(25);
- // 显示Toast
- toast.show();
40、垂直的seekbar
http://blog.csdn.net/liangguo03/article/details/7048793
http://blog.csdn.net/dreambegin/article/details/7196167 可以用这个,效果好
41、spinner控件详解
http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0105/2264.html
42、递归遍历文件夹下的所有文件
- public static List<File> getFileList(String strPath) {
- File dir = new File(strPath);
- File[] files = dir.listFiles(); // 该文件目录下文件全部放入数组
- if (files != null) {
- for (int i = 0; i < files.length; i++) {
- String fileName = files[i].getName();
- if (files[i].isDirectory()) { // 判断是文件还是文件夹
- getFileList(files[i].getAbsolutePath()); // 获取文件绝对路径
- } else if (fileName.endsWith("avi")) { // 判断文件名是否以.avi结尾
- String strFileName = files[i].getAbsolutePath();
- System.out.println("---" + strFileName);
- filelist.add(files[i]);
- } else {
- continue;
- }
- }
- }
- return filelist;
- }
补充阅读:
FilenameFilter的使用
http://www.cnblogs.com/azhqiang/p/4596783.html
43、最近在用android studio 用了一个gitup上的下拉刷新库,样式是挺美观的
https://github.com/android-cjj/Android-MaterialRefreshLayout
主要功能是在viewPager里放了4个fragment,滑动时切换4个页面,每个页面都有下拉刷新功能,出现一个问题,当加入以下代码容易出现报错(前2个fragment正常,第34个fragment就报错)
- //切换页面
- viewPager.setCurrentItem(type);
- java.lang.NullPointerException
- at com.cjj.MaterialRefreshLayout.setProgressValue(MaterialRefreshLayout.java:393)
- at com.cjj.MaterialRefreshLayout.finishRefreshing(MaterialRefreshLayout.java:484)
- at com.cjj.MaterialRefreshLayout$2.run(MaterialRefreshLayout.java:492)
- at android.os.Handler.handleCallback(Handler.java:733)
- at android.os.Handler.dispatchMessage(Handler.java:95)
- at android.os.Looper.loop(Looper.java:136)
- at android.app.ActivityThread.main(ActivityThread.java:5072)
- at java.lang.reflect.Method.invokeNative(Native Method)
- at java.lang.reflect.Method.invoke(Method.java:515)
- at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
- at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
- at dalvik.system.NativeStart.main(Native Method)
上网搜索了下一,发现出现同样的问题同学也不少
https://github.com/android-cjj/Android-MaterialRefreshLayout/issues/35
解决办法 先用google官方的swipeRefreshLayout代替先 ,这里记录下
44、webview使用的一些总结
http://www.cnblogs.com/tony-yang-flutter/p/3565023.html
(1)不跳转到系统的浏览器,直接在当前webview中打开当前地址(其实只要setWebviewClient(new WebviewClient()也行,不用重新里面的方法)
- webview.setWebViewClient(new WebViewClient() {
- @Override
- public boolean shouldOverrideUrlLoading(WebView view, String url) {
- view.loadUrl(url)
- return true;//这里如果用view.stopLoading()可以不执行url的加载,相当于拦截了当前的url请求
- }
- });
(2)允许弹出js窗口
- webSettings.setJavaScriptEnabled(true); // 设置WebView属性,能够执行Javascript脚本
- webSettings.setJavaScriptCanOpenWindowsAutomatically(true);// 可以弹出js弹窗
- webview.setWebChromeClient(new WebChromeClient()); // 在加载网页前加上这句就可以了,用于加载js他弹出窗口
(3)
- //如果不做任何处理,浏览网页,点击系统“Back”键,整个Browser会调用finish()而结束自身
- //,如果希望浏览的网 页回退而不是推出浏览器,需要在当前Activity中处理并消费掉该Back事件。
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
- webView.goBack();//退回到上一个页面
- return true;
- }
- return super.onKeyDown(keyCode, event);
- }
(4)
- //显示进度
- webView.setWebChromeClient(new WebChromeClient(){
- @Override
- public void onProgressChanged(WebView view, int newProgress) {
- Log.e("newProgress", newProgress+"");
- progressBar.setProgress(newProgress);
- if(newProgress >= 100){
- progressBar.setVisibility(View.GONE);
- }
- super.onProgressChanged(view, newProgress);
- }
- });
点击打开链接
45、AlertDialog是系统自带的一个常用的dialog,非常常用
(1)使用系统自带的
- new AlertDialog.Builder(getActivity())
- .setTitle("标题文字")
- .setItems(“自己的数组”, new DialogInterface.OnClickListener() {
- /**当点击对话框的列表项时,回调该方法
- * dialog:AlertDialog
- * which:你点了哪一个列表项
- */
- @Override
- public void onClick(DialogInterface dialog, int which) {
- }
- })
- .create()
- .show();
(2)dialog的内容可以自己定义
- AlertDialog dialog1 = new AlertDialog.Builder(getActivity()).create();
- ImageView imgView=null;
- try {
- imgView = creatNewView()//创建一个新的图片
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- dialog1.show(); //注意这里的顺序不能乱
- dialog1.setContentView(imgView);
(3)
http://blog.csdn.net/bitian123/article/details/51982038设置dialog宽度为屏幕宽度:
Window window = dialog.getWindow();
window.setGravity(Gravity.BOTTOM); //此处可以设置dialog显示的位置window.setWindowAnimations(R.style.anim_push_out); //添加动画
dialog.show(); //注意,参数的设置必须放在show方法后面,否则会报错
//设置dialog的宽度和手机宽度一样
WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
lp.width = window.getWindowManager().getDefaultDisplay().getWidth();
dialog.getWindow().setAttributes(lp);//设置宽度
但是往往dialog还是会有margin,
这时可以给这个AlertDialog设置自定义的样式:
AlertDialog dialog = new AlertDialog.Builder(new ContextThemeWrapper(context, R.style.MyAlertDialog))
.setView(view)
.create();
在样式中把margin设为为负数:
<style name="MyAlertDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="Android:layout_marginLeft">-10dp</item>
<item name="android:layout_marginRight">-10dp</item>
<item name="android:layout_marginBottom">-5dp</item>
</style>
这样这个AlertDialog就是宽度为屏幕宽度,并且和底部没有margin的了。
(4)rd项目中,dialog的设置为全屏自己的代码参考
- note_dlg = new NoteDialog(context, BookShower.this, subType);
- note_dlg.show();
- //以下代码必须放在dialog.show()方法后,否则会报错
- //设置dialog全屏
- //"http://bbs.csdn.net/topics/390175091"
- Window win = note_dlg.getWindow();
- win.getDecorView().setPadding(0, 0, 0, 0);//默认还是有padding 所以还要这么设置
- WindowManager.LayoutParams lp = win.getAttributes();
- lp.width = WindowManager.LayoutParams.MATCH_PARENT;
- lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
- win.setAttributes(lp);
46、
解决Android Studio Gradle Build Running 特别慢的问题
内容为:
org.gradle.daemon=true
-Xmx2048m
-XX:MaxPermSize=2048m
-XX:ReservedCodeCacheSize=1024m
- Toast to=Toast.makeText(MemoActivity.this, "保存成功", 1);
- LinearLayout linearLayout = (LinearLayout) to.getView();
- extView messageTextView = (TextView) linearLayout.getChildAt(0);
- messageTextView.setTextSize(23f);
- to.show();
49、
出现这个问题,注意检查下,子线程不能做ui操作
convertView.setLayoutParams(params);
上网后找到了原因:因为adapter里面的item的布局是LinearLayout,把它改为RelativeLayout即可
参考网址 :http://www.imooc.com/qadetail/83537
正确的代码如下
51、使用context启动Activity要注意的问题
52、使用谷歌官方的drawerLayout,当弹出侧滑菜单会把主界面遮盖,如果想主界面也一同移动使用下面的代码
- https://segmentfault.com/q/1010000006682881 主界面不要被覆盖 参考网址
- drawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {
- @Override
- public void onDrawerSlide(View drawerView, float slideOffset) {
- linearLayout.setTranslationX(slideOffset * drawerView.getWidth());
- // http://blog.csdn.net/adfsadsfa/article/details/43481929 取消主界面透明度变化 先不要
- // drawerLayout.setScrimColor(0x00ffffff);
- }
53、版本4.4-5.1界面侵入状态栏,想给状态栏设置颜色
- //下面的是当4.4版本,contentView会侵入状态栏,所以设置了一个padding,并给状态栏设置颜色
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT <=21)
- {
- //因为整个界面侵入了状态栏,所以把整体布局往下拉,注意这里布局移动是linearLayout,而不是contentView
- int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
- int statusBarHeight = getResources().getDimensionPixelSize(resourceId);
- linearLayout.setPadding(0, statusBarHeight, 0, 0);//linearLayout就是主界面的布局
- getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);//使 ContentView 内容覆盖状态栏
- //下面5句是设置状态栏的颜色,只适用于4.4-5.1版本之间的修改
- ViewGroup contentView = (ViewGroup) this.findViewById(android.R.id.content);
- View statusBarView = new View(this);
- ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
- getStatusBarHeight(this));
- statusBarView.setBackgroundColor(Color.parseColor("#66CCFF"));
- contentView.addView(statusBarView, lp);
- }
54、版本5.1以上设置状态栏颜色
- public void smoothSwitchScreen() {
- if (Build.VERSION.SDK_INT >=22) {
- getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);//使 ContentView 内容不再覆盖状态栏
- //需要设置这个 flag 才能调用 setStatusBarColor 来设置状态栏颜色
- getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
- getWindow().setStatusBarColor(Color.parseColor("#66CCFF")); //当使用这个方法,activity里面的主题也不要使用darkPrimaryColor属性了
- }
55、全屏activity切换到非全屏activity时候,出现黑边和卡顿问题,参考下面的网址
http://blog.csdn.net/u013011318/article/details/48296869
56、把旧文件拷贝到新文件的方法
- /**
- * 拷贝目标文件到新的文件下
- *
- * @param oldFile
- * @param newFile
- */
- private static void copyFile(File oldFile, File newFile) {
- FileOutputStream outputStream = null;
- FileInputStream inputStream = null;
- try {
- outputStream = new FileOutputStream(newFile, true);
- inputStream = new FileInputStream(oldFile);
- byte[] byt = new byte[1024];
- int length = inputStream.read(byt);
- while (length != -1) {
- outputStream.write(byt, 0, length);
- length = inputStream.read(byt);
- }
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (outputStream != null) {
- try {
- outputStream.close();
- } catch (IOException e) {
- }
- }
- if (inputStream != null) {
- try {
- inputStream.close();
- } catch (IOException e) {
- }
- }
- }
- }
57、一个类似word搜索的,搜索关键字黄色高亮的代码,核心代码是用到了
SpannableStringBuilder
参考网址:http://www.jianshu.com/p/f004300c6920
逻辑思路是在BaseAdapter里面的getView方法里,根据关键词的索引
- int index=meetVO.meetingName.indexOf(key);//查找文字在字符串里面第一次出现的索引值
- SpannableStringBuilder spannableString = new SpannableStringBuilder();
- spannableString.append(meetVO.meetingName);
- BackgroundColorSpan bgColorSpan = new BackgroundColorSpan(Color.parseColor("#FFE03D"));//设置背景色为黄色
- spannableString.setSpan(bgColorSpan, index,index+key.length(), Spannable.SPAN_EXCLUSIVE_INCLUSIVE); //这里的key就是关键词
- holder.mTitle.setText(spannableString);//这里的关键字要加黄色背景色
58、一个手机号码格式的正则表达式
http://www.jianshu.com/p/b1d8c6928bad
直接使用下面的字符串即可
(?:(?:(?:13[0-9])|(?:14[57])|(?:15[0-35-9])|(?:17[36-8])|(?:18[0-9]))\d{8})|(?:170[057-9]\d{7})
http://blog.csdn.net/dongbeitcy/article/details/52768074
- public class LoadingDialogIos extends Dialog {
- private TextView tips_loading_msg;
- private String message ;
- private Context context;
- /**
- * 构造方法
- *
- * @param context
- * 上下文
- * @param layoutResId
- * 要传入的dialog布局文件的id
- */
- public LoadingDialogIos(Context context,String msg) {
- super(context, R.style.loadingDialogStyle);//这个样式必须要有,否则出现黑色边框外面还有白色背景框的情况
- this.message = msg;
- this.context=context;
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- this.setContentView( R.layout.view_tips_loading2);
- if (android.os.Build.VERSION.SDK_INT > 22) {//android 6.0替换clip的加载动画
- Drawable drawable = context.getApplicationContext().getResources().getDrawable(R.drawable.loading_for_android6);
- ProgressBar pBar=(ProgressBar) findViewById(R.id.pBar);
- pBar.setIndeterminateDrawable(drawable);
- }
- //输入提示文本框的文字
- tips_loading_msg = (TextView) findViewById(R.id.tips_loading_msg);
- if(!TextUtils.isEmpty(message)){
- tips_loading_msg.setVisibility(View.VISIBLE);
- tips_loading_msg.setText(message);
- }
- }
- }
- <!-- 加载框样式 -->
- <style name="loadingDialogStyle" parent="android:Theme.Dialog">
- <item name="android:windowBackground">@android:color/transparent</item>
- <item name="android:windowFrame">@null</item>
- <item name="android:windowNoTitle">true</item>
- <item name="android:windowIsFloating">true</item>
- <item name="android:windowIsTranslucent">true</item>
- <item name="android:windowContentOverlay">@null</item>
- </style>
loadingDialog的布局
- <?xml version="1.0" encoding="UTF-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:background="@drawable/tips_bg"
- android:gravity="center" >
- <View
- android:layout_width="80dip"
- android:layout_height="80dip"
- android:layout_centerInParent="true" />
- <LinearLayout
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerInParent="true"
- android:orientation="vertical" >
- <ProgressBar
- android:id="@+id/pBar"
- android:layout_width="50dp"
- android:layout_height="50dp"
- android:layout_gravity="center"
- android:layout_marginBottom="1dp"
- android:clickable="false"
- android:gravity="center"
- android:indeterminateDrawable="@drawable/loading" />
- <TextView
- android:id="@+id/tips_loading_msg"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:gravity="center"
- android:lineSpacingExtra="3.0dip"
- android:visibility="gone"
- android:layout_marginTop="7dp"
- android:textColor="#ffffffff"
- android:textSize="15sp" />
- </LinearLayout>
- </RelativeLayout>
- @drawable/loading的代码
- <?xml version="1.0" encoding="UTF-8"?>
- <animation-list xmlns:android="http://schemas.android.com/apk/res/android"
- android:oneshot="false" >
- <item android:duration="150">
- <clip
- android:clipOrientation="horizontal"
- android:drawable="@drawable/ic_loading_white_01"
- android:gravity="left" />
- </item>
- <item android:duration="150">
- <clip
- android:clipOrientation="horizontal"
- android:drawable="@drawable/ic_loading_white_02"
- android:gravity="left" />
- </item>
- <item android:duration="150">
- <clip
- android:clipOrientation="horizontal"
- android:drawable="@drawable/ic_loading_white_03"
- android:gravity="left" />
- </item>
- <item android:duration="150">
- <clip
- android:clipOrientation="horizontal"
- android:drawable="@drawable/ic_loading_white_04"
- android:gravity="left" />
- </item>
- <item android:duration="150">
- <clip
- android:clipOrientation="horizontal"
- android:drawable="@drawable/ic_loading_white_05"
- android:gravity="left" />
- </item>
- <item android:duration="150">
- <clip
- android:clipOrientation="horizontal"
- android:drawable="@drawable/ic_loading_white_06"
- android:gravity="left" />
- </item>
- <item android:duration="150">
- <clip
- android:clipOrientation="horizontal"
- android:drawable="@drawable/ic_loading_white_07"
- android:gravity="left" />
- </item>
- <item android:duration="150">
- <clip
- android:clipOrientation="horizontal"
- android:drawable="@drawable/ic_loading_white_08"
- android:gravity="left" />
- </item>
- <item android:duration="150">
- <clip
- android:clipOrientation="horizontal"
- android:drawable="@drawable/ic_loading_white_09"
- android:gravity="left" />
- </item>
- <item android:duration="150">
- <clip
- android:clipOrientation="horizontal"
- android:drawable="@drawable/ic_loading_white_10"
- android:gravity="left" />
- </item>
- <item android:duration="150">
- <clip
- android:clipOrientation="horizontal"
- android:drawable="@drawable/ic_loading_white_11"
- android:gravity="left" />
- </item>
- <item android:duration="150">
- <clip
- android:clipOrientation="horizontal"
- android:drawable="@drawable/ic_loading_white_12"
- android:gravity="left" />
- </item>
- </animation-list>
- loading_for_android6的代码
- <?xml version="1.0" encoding="UTF-8"?>
- <animation-list xmlns:android="http://schemas.android.com/apk/res/android"
- android:oneshot="false"
- android:variablePadding="true" >
- <item
- android:drawable="@drawable/ic_loading_white_01"
- android:duration="100"
- android:gravity="center">
- </item>
- <item
- android:drawable="@drawable/ic_loading_white_02"
- android:duration="100"
- android:gravity="center">
- </item>
- <item
- android:drawable="@drawable/ic_loading_white_03"
- android:duration="100"
- android:gravity="center">
- </item>
- <item
- android:drawable="@drawable/ic_loading_white_04"
- android:duration="100"
- android:gravity="center">
- </item>
- <item
- android:drawable="@drawable/ic_loading_white_05"
- android:duration="100"
- android:gravity="center">
- </item>
- <item
- android:drawable="@drawable/ic_loading_white_06"
- android:duration="100"
- android:gravity="center">
- </item>
- <item
- android:drawable="@drawable/ic_loading_white_07"
- android:duration="100"
- android:gravity="center">
- </item>
- <item
- android:drawable="@drawable/ic_loading_white_08"
- android:duration="100"
- android:gravity="center">
- </item>
- <item
- android:drawable="@drawable/ic_loading_white_09"
- android:duration="100"
- android:gravity="center">
- </item>
- <item
- android:drawable="@drawable/ic_loading_white_10"
- android:duration="100"
- android:gravity="center">
- </item>
- <item
- android:drawable="@drawable/ic_loading_white_11"
- android:duration="100"
- android:gravity="center">
- </item>
- <item
- android:drawable="@drawable/ic_loading_white_12"
- android:duration="100"
- android:gravity="center">
- </item>
- </animation-list>
打开PullToRefreshListView这个类所继承的抽象类:PullToRefreshAdapterViewBase<T extends AbsListView> extends PullToRefreshBase<T> implements OnScrollListener 自己添加了一个方法:
- public void setOnItemLongClickListener(OnItemLongClickListener listener){
- mRefreshableView.setOnItemLongClickListener(listener);
- }
61、集合里面,按照对象的某个字段进行排序,这里的newData是个ArrayList的集合,里面的每个对象就是Im,im对象里面有个personStationName的字段,现在需要按照这个字段进行排序
- <span style="white-space:pre"> </span>//得到的newData应该还要按分组名单personStationName字段进行排序 否则显示数据较为杂乱
- <span style="white-space:pre"> </span>//Collections 是集合的公共类,提供各种工具,其中提供了排序方法
- <span style="white-space:pre"> </span>Collections.sort(newData,new Comparator<Im>() {
- /* http://blog.csdn.net/lifuxiangcaohui/article/details/41543347
- * 如果比较的是数字
- * int compare(Student o1, Student o2) 返回一个基本类型的整型,
- * 返回负数表示:o1 小于o2,
- * 返回0 表示:o1和o2相等,
- * 返回正数表示:o1大于o2。
- */
- @Override
- public int compare(Im im1, Im im2) {
- //http://blog.csdn.net/one_isi_all/article/details/50036137
- //按照机构名字进行排序
- return im1.personStationName.compareTo(im2.personStationName);
- }
- });