forked from organicmaps/organicmaps
[android] Fix crash with adding new category.
This commit is contained in:
parent
4f7034da04
commit
c4faa9c36c
4 changed files with 37 additions and 28 deletions
|
@ -19,7 +19,8 @@ public abstract class AbstractBookmarkCategoryActivity extends AbstractBookmarkL
|
|||
if (menuInfo instanceof AdapterView.AdapterContextMenuInfo)
|
||||
{
|
||||
final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
|
||||
if (getAdapter().isActiveItem(info.position))
|
||||
final BookmarkCategoriesAdapter adapter = (BookmarkCategoriesAdapter)getAdapter();
|
||||
if (adapter.isActiveItem(info.position))
|
||||
{
|
||||
mSelectedPosition = info.position;
|
||||
menu.setHeaderTitle(mManager.getCategoryById(mSelectedPosition).getName());
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package com.mapswithme.maps.bookmarks;
|
||||
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.BaseAdapter;
|
||||
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
|
||||
public abstract class AbstractBookmarkCategoryAdapter extends BaseAdapter
|
||||
{
|
||||
private final BookmarkManager mManager;
|
||||
|
@ -30,7 +30,7 @@ public abstract class AbstractBookmarkCategoryAdapter extends BaseAdapter
|
|||
@Override
|
||||
public int getCount()
|
||||
{
|
||||
return mManager.getCategoriesCount() + 1;
|
||||
return mManager.getCategoriesCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -39,28 +39,6 @@ public abstract class AbstractBookmarkCategoryAdapter extends BaseAdapter
|
|||
return position;
|
||||
}
|
||||
|
||||
public final static int ITEM = 0;
|
||||
public final static int HELP = 1;
|
||||
@Override
|
||||
public int getItemViewType(int position)
|
||||
{
|
||||
if (position == getCount() - 1) return HELP;
|
||||
return ITEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewTypeCount()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public boolean isActiveItem(int position)
|
||||
{
|
||||
return getItemViewType(position) != HELP
|
||||
&& position < getCount()
|
||||
&& position >= 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BookmarkCategory getItem(int position)
|
||||
{
|
||||
|
|
|
@ -43,7 +43,8 @@ public class BookmarkCategoriesActivity extends AbstractBookmarkCategoryActivity
|
|||
public void onCreateContextMenu(ContextMenu menu, View v,
|
||||
ContextMenuInfo menuInfo)
|
||||
{
|
||||
if (getAdapter().isActiveItem(((AdapterView.AdapterContextMenuInfo)menuInfo).position))
|
||||
final BookmarkCategoriesAdapter adapter = (BookmarkCategoriesAdapter)getAdapter();
|
||||
if (adapter.isActiveItem(((AdapterView.AdapterContextMenuInfo)menuInfo).position))
|
||||
{
|
||||
getMenuInflater().inflate(R.menu.bookmark_categories_context_menu, menu);
|
||||
super.onCreateContextMenu(menu, v, menuInfo);
|
||||
|
|
|
@ -19,6 +19,35 @@ public class BookmarkCategoriesAdapter extends AbstractBookmarkCategoryAdapter
|
|||
super(context);
|
||||
}
|
||||
|
||||
private final static int ITEM = 0;
|
||||
private final static int HELP = 1;
|
||||
|
||||
@Override
|
||||
public int getCount()
|
||||
{
|
||||
return super.getCount() + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position)
|
||||
{
|
||||
if (position == getCount() - 1) return HELP;
|
||||
return ITEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewTypeCount()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public boolean isActiveItem(int position)
|
||||
{
|
||||
return getItemViewType(position) != HELP
|
||||
&& position < getCount()
|
||||
&& position >= 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue