Android学习笔记(八)

onSaveInstanceState和SharedPreferences
        前者是方法,而后者是一个对象。两者的相同点都是能够进行简单的数据的存储。只是前者是一种被动的,而后者是一种主动式的存储。
        onSaveInstance的说明是will be triggered whenever an Activity completes it's Active life cycle,but only when it's not being explicitly finished.由此可见,这种适合那种activity是线性变化的保存,由于是线性变化,所以手动保存就变的很麻烦。
        SharePreferences则是一种纯手工的操作。这种估计是大多数app最常用的方式。
        当然,我还想到了两者的竞争。不过仔细想想,其实两者是很难产生竞争的。毕竟当需要记录时,记录的目的或者要求往往固定。很难产生一种两种都需要的情况。就算产生。也可以通过往两者之间加入时间戳,或者其他比较来区分。

KeyListener和OnKeyListener 
        说句实话,在写这个的时候,我还没有搞清楚两者的区别。
         Sets the key listener to be used with this TextView. This can be null to disallow user input. Note that this method has significant and subtle interactions with soft keyboards and other input method: see KeyListener.getContentType() for important details. Calling this method will replace the current content type of the text view with the content type returned by the key listener.
          这是Api关于KeyListener的评述。这里注意两点。第一个点说明了。如果输入null,会取消用户的输入。这点很有意思。同时也说明其实KeyListener是会影响交互的。这也就是为什么。在用了这个之后,我发觉我没有办法输入了。(当时我不是输入null,而是只是继承了接口,重写了一个方法而已。但是输入也被disable了)
           关于第二个,我也很糊涂。一知半解。有点感觉是不能控制的原因。
        处理字符要用OnKeyListener。

Text的Hint。
      怎么说呢,知道一下就ok了。不错的东西,可以省一个label的位置。有时候在比较小的手机界面中,少一个label能够很方便布局。

 

你可能感兴趣的:(android)