I need some examples or tutorial, how to implement iPhone side index for Android.
I read already this topic (http://stackoverflow.com/questions/1201962/android-equivalent-to-iphone-indexed-uitableview) and I'm trying AlphabetIndexer, but:
- How do I create it properl at all?
- How can be AlphabetIndexer displayed?!
- Is an extra layout schema for indexed lists already defined?
UPD:
If you downvote the topic, could you at least argue, why.
Thank you
Mur
Ps. I give you a bit of my code:
static String[] COUNTRIES = new String[] {"Ammensdorf", "Afghanistan", "Albania" ..};
static List<String> countryList = Arrays.asList(COUNTRIES);
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView lv1=(ListView)findViewById(R.id.ListView01);
// By using setAdpater method in listview we an add string array in list.
// lv1.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 , COUNTRIES));
Cursor c1 = createCursor(COUNTRIES);
MyAdapter sortedAdapter = new MyAdapter(this, R.layout.list_item_extended, c1, new String[] {"country"},
new int[] {R.id.list_item_extended});
lv1.setAdapter(sortedAdapter);
}
private Cursor createCursor(String[] listData)
{
MatrixCursor matrixCursor = null;
String[] menuCols = new String[] {"_id", "country"};
matrixCursor = new MatrixCursor(menuCols);
int i = -1;
Object[] tmpArr = new Object[2];
String tmpLetter = null;
String currentLetter = null;
for (String country: countryList)
{
currentLetter = country.substring(0, 1);
if (!currentLetter.equals(tmpLetter))
{
tmpLetter = currentLetter;
i++;
}
tmpArr[0] = i;
tmpArr[1] = country;
matrixCursor.addRow(tmpArr);
}
return matrixCursor;
}
private static class MyAdapter extends SimpleCursorAdapter implements SectionIndexer
{
private AlphabetIndexer mIndexer;
public MyAdapter(Context context, int layout, Cursor c, String[] from, int[] to)
{
super(context, layout, c, from, to);
String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
mIndexer = new AlphabetIndexer(c, 0, alphabet);
}
public int getPositionForSection(int section) {
return mIndexer.getPositionForSection(section);
}
public int getSectionForPosition(int position) {
return mIndexer.getSectionForPosition(position);
}
public Object[] getSections() {
return mIndexer.getSections();
}
}