Android中遇到的需求与解决方案一

来源:互联网 发布:显示器连接网络机顶盒 编辑:程序博客网 时间:2024/05/21 18:12

1.需求:让Android SDk 2.3的版本的EditView的输入框样式用上SDK 4.0的样式。

①.在F:\sdk\sdk\platforms\android-14\data\res\drawable-xhdpi文件夹下,找到textfield_activated_holo_dark.9.png图片与textfield_default_holo_light.9.png,相应的图片如图:


②在定义相应的样式如下:

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android" >        <item android:drawable="@drawable/textfield_activated_holo_dark" android:state_pressed= "true"/>      <item android:drawable="@drawable/textfield_activated_holo_dark" android:state_focused= "true"/>      <item android:drawable="@drawable/textfield_activated_holo_dark" android:state_selected= "true"/>      <item android:drawable="@drawable/textfield_default_holo_light" />    </selector>

这样只要设置背景为样式就可以了。

2.需求:让Android SDk4.0的版本的EditView的输入框样式用上SDK2.3的样式。

在xml中的editview的布局设置中加上:系统提供的2.2黄色的编辑框背景

android:background="@android:drawable/editbox_background"

3.需求:让EditView初始默认显示多行。为了界面美观。

android:inputType="textMultiLine"//可以显示多行android:gravity="left|top"//输入时光标左上角android:minLines="3" //最小显示3行


4.需求:取消Editview的默认选中。

只需要在这editview的父控件或者别的控件中设置android:focusable="true" ;android:focusableInTouchMode="true"。


5.需求:根据一个已知的URL路径获取文件名称。

例如从(http://d.hiphotos.baidu.com/image/pic/item/4bed2e738bd4b31c54ee9cc785d6277f9f2ff8f8.jpg),获取文件的名称(4bed2e738bd4b31c54ee9cc785d6277f9f2ff8f8.jpg)。

String tmpUrl ="http://d.hiphotos.baidu.com/image/pic/item/4bed2e738bd4b31c54ee9cc785d6277f9f2ff8f8.jpg";String imageName = tmpUrl.substring(tmpUrl.lastIndexOf("/") + 1);

6.需求:需要遍历SD卡中某个文件夹中的某种类型的文件。

private List<String> lstFile = new ArrayList<String>();  //结果 List public void GetFiles(String Path, String Extension, boolean IsIterative)  //搜索目录,扩展名,是否进入子文件夹{    File[] files = new File(Path).listFiles();     for (int i = 0; i < files.length; i++)    {        File f = files[i];        if (f.isFile())        {            if (f.getPath().substring(f.getPath().length() - Extension.length()).equals(Extension))  //判断扩展名                lstFile.add(f.getPath());             if (!IsIterative)                break;        }        else if (f.isDirectory() && f.getPath().indexOf("/.") == -1)  //忽略点文件(隐藏文件/文件夹)            GetFiles(f.getPath(), Extension, IsIterative);    }}
判断拓展名之后便是得到的一个一个符合要求的文件,可以做相应的处理。


7.需求:获取当前时间到1970-01-01的秒数和获取某个文件的最后更改时间。

System.currentTimeMillis()

String fileName = "/sdcard/pgis/xxx.jpg";File f =new File(fileName);f.lastModified();

这两个方法获取的时间都是1970-01-01到至今的秒数。

8.需求:在Arcgis For Android中,需要给新建的Graphic添加一些标识符或者自带的内容参数。

Map<String, Object> caseMap = new HashMap<String, Object>();caseMap.put("context", calloutString);caseMap.put("genre", "case");PictureMarkerSymbol pms = new PictureMarkerSymbol(drawable);Graphic gp = new Graphic(point, pms, caseMap);

代码中,新建一个map,然后传递键值对进去,在新建gp时,就直接附带进去,接下来在需要使用的地方:

String graphicGenre = (String) gp.getAttributeValue("genre");(String) gp.getAttributeValue("context")

这样就可以直接取出gp中的genre与context所对应的字符串内容。该技术也可用于识别一个GraphicLayer中不同种类的Graphic。

9.需求:设置ListView的item选中背景变白色且不回弹。

看了网络上很多新建drawable中的xml文件,设置按下、选中、离开各种颜色背景,并将List设置为单选模式。测试发现,效果都不如人愿,手一离开选中的item,就马上回复到了list的初始背景色。

解决方法:*首先去除list的单选模式:

listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

*接着在布局的xml中的list中设置背景颜色和选中更改颜色。

 <ListView            android:id="@+id/list"            android:layout_width="match_parent"            android:layout_height="match_parent"            android:background="@color/survey_list_background"            android:listSelector="@color/white" >        </ListView>

于是需求解决,以前都是什么自定义listview,修改getView方法各种麻烦的方式。如果不是特别要求,建议简单设置实现需求。


10.需求:Arcgis 中设置Layer一直位于最顶层。

就是有很多个GraphicLayer添加到MapView上,如果不设置的话就是默认的添加顺序最后添加的图层在最顶层,最早添加的在最底层。那么现在我希望我最早添加的图层能时刻都是在最顶层。

如下图,只要设置好index的顺序就好了,值越小,就处于地图越底层。


0 0
原创粉丝点击