做项目遇到的点点点滴滴(持续更新)

1.我想实现一个EditText点击后出现DatePickerDialog然后返回值到EditText显示。
做完之后发现点击EditText只是触发焦点或者弹出软键盘(我把软键盘禁用之后就只触发焦点)
然后在获得焦点之后再次点击才会出现DatePickerDialog...
方法一:这个是在View里定义onTouchEvent()的默认处理逻辑。假如一个View是可以获得焦点的话,那么第一次点击操作就是获取焦点。这里有源代码:

  boolean focusTaken = false;
                        if (isFocusable() && isFocusableInTouchMode() && !isFocused()) {
                            focusTaken = requestFocus();
                        }

                        if (!mHasPerformedLongPress) {
                            // This is a tap, so remove the longpress check
                            removeLongPressCallback();

                            // Only perform take click actions if we were in the pressed state
                            if (!focusTaken) {
                                // Use a Runnable and post this rather than calling
                                // performClick directly. This lets other visual state
                                // of the view update before click actions start.
                                if (mPerformClick == null) {
                                    mPerformClick = new PerformClick();
                                }
                                if (!post(mPerformClick)) {
                                    performClick();
                                }
                            }
                        }

所以如果你想改变这个的话,只能自己重新实现一个onTouchEvent()而不调用super.onTouchEvent(),注意参考源代码。


方法二:设置edittext不能获取到焦点.就OK了,即在TextView中加入android:focusable="false"


2.一个textView点击后跳转到另一个页面。 

刚开始此textView没有跑马灯效果,布局如下: 
        <TextView 
            android:id="@+id/title" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:textSize="25px" /> 

后来觉得加上跑马灯效果更好点,故布局如下: 
        <TextView 
            android:id="@+id/title" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:ellipsize="marquee" 
            android:focusable="true" 
            android:focusableInTouchMode="true" 
            android:marqueeRepeatLimit="marquee_forever" 
            android:scrollHorizontally="true" 
            android:singleLine="true" 
            android:textSize="25px" /> 

但问题出现了,用上面的布局,点击之后会进行页面的跳转,用下面的布局,跑马灯效果是有了,但点击textView后不进行页面的跳转。 
那么我应该如何实现了?求解答。

方法:删除android:focusable="true",原理:android:focusable="true" ,这样当你点击时其实是点击的是textView,从而textView获取焦点而不是listView中的某一列获取焦点,当然也就不会触发onListItemClick方法,这样当然也就不会进行页面的跳转了。解决方法是:删去这个属性,就OK了!

3.201200920 -----今天又遇到个问题。android手机联互联网问题!如何判断手机是否连接互联网?本来以为很简单,以为直接调用下面的方法就可以了

/**

* 检查网络连接情况

* @return 0: None, 1: Wifi, 2: GPRS, 3: Other

*/

protected static int checkNetworkType(Context context) {

ConnectivityManager connManager = (ConnectivityManager) context

.getSystemService(Context.CONNECTIVITY_SERVICE);

// 获取代表联网状态的NetWorkInfo对象

NetworkInfo networkInfo = connManager.getActiveNetworkInfo();

// 获取当前的网络连接是否可用

if (networkInfo == null || !networkInfo.isAvailable())

return 0;

// Wifi

State state = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)

.getState();

if (State.CONNECTED == state) {

return 1;

}

// GPRS

state = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)

.getState();

if (State.CONNECTED == state) {

return 2;

}

return 3;

}

其实不然,我发现当手机关闭GPRS,然后连接公司的wifi,通知栏显示wifi已经连接上,并且这个方法返回值为1,我就默认为此时我们的手机已经联网了,但实际发现此时手机还是打不开网页,对应到项目中来就是我们不能从服务器获取信息。

后来想想可能是因为我们连接了wifi,但此时公司路由器并没有连外网,所以还是打不开网页,也获取不了服务器信息。怎么解决判断手机是否连接外网暂时还没有想到,继续研究....

4.20120921项目交给测试部门测试(其实自己也觉得有很多bug)

今天遇到的问题:项目在A手机上能够后运行,B手机上也能够运行,但在C手机上就运行不起来。出现:Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY的错误。在网上一查,大部分的人都说是我建工程的时候target没有选google map的target,但奇怪的是我建的项目就是google map的target。后来看到一篇文章,试着解决,终于解决了。链接:http://www.cnblogs.com/jrvin/archive/2011/05/24/2055718.html

其中遇到过Read-only file system问题,但这都是些小问题,最后还是解决了!

5.20120922项目测试又出现了一个问题,关于camera问题。竖屏拍完照传到服务器相片是逆时针旋转90度的。目前没有解决。。。努力中!

20120923,今天解决了竖屏拍完照传到服务相片是逆时针旋转90度的问题,解决代码如下:

private PictureCallback pictureCallBack = new Camera.PictureCallback() {

public void onPictureTaken(byte[] data, Camera camera) {

if (mCam != null) {

if (data != null) {

/* 为了解决保存相片旋转90度的问题 */

Bitmap bMap = BitmapFactory.decodeByteArray(data, 0,

data.length);

Matrix matrix = new Matrix();

matrix.reset();

matrix.postRotate(90);

Bitmap bMapRotate = Bitmap.createBitmap(bMap, 0, 0,

bMap.getWidth(), bMap.getHeight(), matrix, true);

bMap = bMapRotate;

/* end */

f = new File("sdcard/myImage/" + "picture.jpg");

try {

BufferedOutputStream bos = new BufferedOutputStream(

new FileOutputStream(f));

bMap.compress(Bitmap.CompressFormat.JPEG, 100, bos);// 将图片压缩到流中

afterBuildDailog();

bos.flush();// 输出

bos.close();// 关闭

} catch (IOException e) {

e.printStackTrace();

}

}

// finish();

}

}

};

6.20120927今天遇到一个很诡异的问题,LBS位置定位问题。两种定位方式,GPS定位和室内定位,今天要说的是基站定位,当在室内定位时,我是用的基站定位,向http://www.google.com/loc/json中发送一些手机的基本信息,然后google会返回给我们位置,奇怪的是前几天这个功能还好好的,最近几天就很不稳定,时而能够定位,时而不能够定位,不能定位时,用wifi上网看log信息是:java.net.SocketException: The operation timed out,用gprs上网log报的异常是:java.net.SocketException: Netwrok is unreachable。目前这个问题困扰我很久了,仍然没有解决!

7.弹出的对话框在输入的信息不正确的情况下对话框不消失:

使用反射:
在你的setPositiveButton中添加:
//用于不关闭对话框

try { 
Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing"); 
field.setAccessible(true); 
field.set(dialog, false); 


} catch (Exception e) { 
e.printStackTrace(); 
}  

添加上述代码后就可以使dialog无法关闭,在你需要关闭的地方,添加:
//关闭对话框

try {
Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
field.setAccessible(true);
field.set(dialog, true);
} catch (Exception e) {
e.printStackTrace();

现在问题是,当你输入的信息不正确后,点击后退按钮,对话框竟然也不消失。目前木有解决。

猜你喜欢

转载自caik123.iteye.com/blog/1680485
今日推荐