- ExpandableListView裏, 如果在關聯的adapter的getChildView()裏設置了setOnClickListener監聽事件,在expandablelistview.setOnChildClick()綁定子菜單點擊事件是沒有反應的,原因在於兩個監聽有衝突,去掉adapter裏的監聽即可。
- 先創建一個MyApp來extendsApplication, 然後用publict static Context getMyApp() 來return getApplicationContext(). 這樣就可以全局的使用context.
- 如果需要在static method裏啓動Activity, 需要在方法裏把Context作爲參數傳進去,像下邊這樣。否則無法直接啓動。
private static void startApp(Context context) { Intent intent = new Intent(context, MainActivity.class); context.startActivity(intent); }
- LinkedHashMap用起來一點不比Arraylist差,而且可以按照添加的順序排序,並且可以用在listview的數據裏,不過需要先把linkedHashMap的數據簡單轉換成list,方法大致如下:
private LinkedHashMap<Integer, Menu> _mainMenusMap; private LinkedHashMap<Integer, ArrayList<Menu>> _subMenusMap; private ArrayList<Menu> _mainMenusList; private ArrayList<ArrayList<Menu>> _subMenusList; private Context _context; public NavigationDrawerExpandableListAdapter(Context context, LinkedHashMap<Integer, Menu> mainMenusMap, LinkedHashMap<Integer, ArrayList<Menu>> subMenusMap) { this._context = context; this._mainMenusMap = mainMenusMap; this._subMenusMap = subMenusMap; this._mainMenusList = new ArrayList<Menu>(); this._subMenusList = new ArrayList<ArrayList<Menu>>(); _mainMenusList.addAll(_mainMenusMap.values()); _subMenusList.addAll(_subMenusMap.values()); Log.i(Thread.currentThread().getStackTrace()[2].getClassName(), "_mainMenusList size is " + _mainMenusList.size()); Log.i(Thread.currentThread().getStackTrace()[2].getClassName(), "_subMenusList size is " + _subMenusList.size()); }
之後需要用到數據,可以直接採用list數據即可。本例子中用的是expandablelistview,情況稍複雜,但是類似。
- Fragment 保存狀態的問題,尤其是通過按返回按鈕時候,返回的fragment通常不是你最後離開時候的狀態,原因是返回鍵按下後,fragment會重新調用 onCreateView, 所以可以在在構造fragment時候,添加一個bundle 作爲保存狀態用,onPause裏保存需要保存的東西,在onCreateView裏判斷一下bundle是不是爲NULL,不是的話就調用出來保存的狀態。不要指望onSavedInstance, 這個只有在Activity被銷燬,重新創建時候纔會調用。 在只有一個Activity, 很多Fragments的情況下,還是自己來保存狀態吧。
- 如果應用中用到了Splash界面的話,啓動主界面後,按下返回鍵是會回到splash界面的,這時候只要在manifest.xml裏對splashActivity設置一下noHistory=true屬性就可以了,以防止回退到啓動界面。
- EditText不自動獲取焦點方法,在其父類View設置,focusable = true; focusable on touchMode = true;
- 4.2系統後,copyPixelsFromBuffer()之前,需要先調用ByteBuffer的rewind( )byteBuffer的rewind()方法將指針指向0.
- jni裏的方法不能被定義爲static
- SVN revert 時候如果出現提示不能缺少parent版本不能revert時,可以切到文件夾下執行svn revert --depth infinity 來進行整個文件夾的恢復工作。
-
useLibrary 'org.apache.http.legacy' , 解決不能引用deprecated的問題