title: Android alphabets section Listview like contacts app listview
body: <p>now can any one help me how to look my view something like this. please help me i am too confusing.</p>
  
  <p><img src="https://i.stack.imgur.com/HyHVM.png" alt="enter image description here"></p>
  
  <p>here my code:-------</p>
  
  <p>phonebooklistview.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
      &lt;EditText
          android:id="@+id/searchTxtBox"
          android:layout_width="match_parent"
          android:layout_height="40dp"
          android:layout_marginTop="65dp"
          android:hint="@string/searchHintTxt"
          android:singleLine="true"
          android:drawableLeft="@android:drawable/ic_search_category_default"
          android:drawablePadding="0dp"
          android:text="" /&gt;
  
      &lt;ListView
          android:id="@android:id/list"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:fadingEdge="vertical"
          android:fastScrollEnabled="true"
          android:padding="2dp"
          android:layout_below="@+id/searchTxtBox" &gt;
      &lt;/ListView&gt;
  
      &lt;TextView
          android:id="@+id/phoneBookEmptyView"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:gravity="center_horizontal"
          android:layout_gravity="center_horizontal"
          android:text="@string/phoneBookEmptyMsg"
          android:textColor="@color/white"
          android:layout_below="@+id/searchTxtBox"
          android:layout_marginTop="5dp"
          android:textAppearance="?android:attr/textAppearanceMedium" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>and in PhoneBookList.java file </p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
      setContentView(R.layout.phonebooklistview);
  
      listView = getListView();
      adapter = new ItemsAdapter(this);
      adapter.notifyDataSetChanged();
      listView.setAdapter(adapter);
      listView.setTextFilterEnabled(true);
      //listView.setFastScrollEnabled(true);
      listView.setOnItemLongClickListener(this);
      listView.setItemsCanFocus(false);
      listView.setEmptyView(findViewById(R.id.phoneBookEmptyView));
      registerForContextMenu(listView);
  
  }
  
  
  
  private class ItemsAdapter extends BaseAdapter implements SectionIndexer
  {
      HashMap&lt;String, Integer&gt; alphaIndexer;
      String[] sections;
        private LayoutInflater inflater;
        String[][] items;
  
        public ItemsAdapter(Context context)
        {
            inflater = LayoutInflater.from(context);
            this.items = phoneBookDataArr;
  
              alphaIndexer = new HashMap&lt;String, Integer&gt;();
              int size = items.length;
  
              for (int x = 0; x &lt; size; x++)
              {
                  String name=items[x][2];
                  String ch =  name.substring(0, 1);
                  ch = ch.toUpperCase();
                  alphaIndexer.put(ch, x);
  
                  Log.e(TAG,"alphaIndexer="+ch);
              }
  
              Set&lt;String&gt; sectionLetters = alphaIndexer.keySet();
              ArrayList&lt;String&gt; sectionList = new ArrayList&lt;String&gt;(sectionLetters); 
              Collections.sort(sectionList);
              sections = new String[sectionList.size()];
              sectionList.toArray(sections);
        }
  
        //@Override
        public View getView(final int position, View convertView, ViewGroup parent)
        {
      // here my custom listviewcontentview goes.
        }
  
        public int getCount()
        {
            return items.length;
        }
  
        public Object getItem(int position)
        {
            return position;
        }
  
        public long getItemId(int position)
        {
            return 0;
        }
  
        public int getPositionForSection(int section)
        {
            Log.e(TAG,"getPositionForSection="+section);
            return alphaIndexer.get(sections[section]);
        }
  
        public int getSectionForPosition(int position)
        {
            Log.e(TAG,"getSectionForPosition="+position);
            return 1;
        }
  
        public Object[] getSections()
        {
            Log.e(TAG,"getSections="+sections.length);
            for (String str : sections)
            {
              Log.e(TAG,str);
            }
            return sections;
        }
  }
  </code></pre>