Posts

Showing posts from April, 2015

How to hide Soft Keyboard when activity starts ?

In the AndroidManifest.xml <activity android:name="com.your.package.ActivityName"       android:windowSoftInputMode="stateHidden"  /> Also you can use the following functions to show/hide the keyboard /**  * Hides the soft keyboard  */ public void hideSoftKeyboard() {     if(getCurrentFocus()!=null)     {         InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);         inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);     } } /**  * Shows the soft keyboard  */ public void showSoftKeyboard(View view) {     InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);     view.requestFocus();     inputMethodManager.showSoftInput(view, 0); }

How can set list view height based on children ?

- Use this function to change listview size dynamically..... /**     * Sets the list view height based on children.     *     * @param listView     * the new list view height based on children     */     private void setListViewHeightBasedOnChildren(ListView listView)     {         ListAdapter listAdapter = listView.getAdapter();         if (listAdapter == null)             return;         int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(), MeasureSpec.UNSPECIFIED);         int totalHeight = 0;         View view = null;         for (int i = 0; i < listAdapter.getCount(); i++)         {             view = listAdapter.getView(i, view, listView);             if (i == 0)                 view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, LayoutParams.WRAP_CONTENT));             view.measure(desiredWidth, MeasureSpec.UNSPECIFIED);             totalHeight += view.getMeasuredHeight();         }         ViewGroup.LayoutParams params = listView.getLayoutParams();

How can remove duplicate values from ArrayList

- This is solution for remove duplicate values from ArrayList Set<String> set = new LinkedHashSet<String>(); for (ArrayList<String> list:yourList) {     set.addAll (list); } ArrayList<String> uniqueList = new ArrayList<String>(set);

String to ArrayList

How to convert comma separated String value to ArrayList ? Solution : private List<String> items; private String orderedItem = "1,2,3,4,5,6,7,8,9,"; items = new ArrayList<String>(Arrays.asList(orderedItem.split(",")));