I am using Drawer functionality and i am using Fragment-TabHost functionality for fragments and i am using Sherlock action Library for this
Code runs fine but there is a bug in the functionality:: When i click the menu item of the actionBar a toast kind of dialog is displayed as shown in figure below, I have never used toast in the code
Node::keep pressing menu item for 3 sec...then this dialog pops up
MainActivity.java
public class MainActivity extends SherlockFragmentActivity implements OnItemClickListener{
private DrawerLayout drawlayout=null;
private ListView listview=null;
private ActionBarDrawerToggle actbardrawertoggle=null;
private String[] myfriendname=null;
private String[] myfriendnickname=null;
private int[] photo=null;
//Fragment fragment1 = new Fragment1();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myfriendname = new String[] { "Sunil Gupta", "Abhishek Tripathi","Sandeep Pal", "Amit Verma" };
myfriendnickname = new String[] { "sunil android", "Abhi cool","Sandy duffer", "Budhiya jokar"};
photo = new int[] { R.drawable.sunil, R.drawable.abhi, R.drawable.sandy, R.drawable.amit};
drawlayout = (DrawerLayout)findViewById(R.id.drawer_layout);
listview = (ListView) findViewById(R.id.listview_drawer);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(true);
drawlayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
drawlayout.setBackgroundColor(Color.WHITE);
MenuListAdapter menuadapter=new MenuListAdapter(getApplicationContext(), myfriendname, myfriendnickname, photo);
listview.setAdapter(menuadapter);
actbardrawertoggle= new ActionBarDrawerToggle(this, drawlayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close)
{
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
}
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
};
drawlayout.setDrawerListener(actbardrawertoggle);
listview.setOnItemClickListener(this);
if (savedInstanceState == null) {
selectItem(0);
}
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
actbardrawertoggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
actbardrawertoggle.onConfigurationChanged(newConfig);
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
selectItem(position);
}
private void selectItem(int position) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
// Locate Position
switch (position) {
case 0:
Fragment1 fragment1=new Fragment1();
ft.replace(R.id.content_frame, fragment1);
Bundle b = new Bundle();
b.putString("name",myfriendname[position]);
b.putInt("photo",photo[position]);
fragment1.setArguments(b);
break;
case 1:
Fragment2 fragment2=new Fragment2();
ft.replace(R.id.content_frame, fragment2);
Bundle b1 = new Bundle();
b1.putString("name",myfriendname[position]);
b1.putInt("photo",photo[position]);
fragment2.setArguments(b1);
break;
case 2:
Fragment3 fragment3=new Fragment3();
ft.replace(R.id.content_frame, fragment3);
Bundle b2 = new Bundle();
b2.putString("name",myfriendname[position]);
b2.putInt("photo",photo[position]);
fragment3.setArguments(b2);
break;
case 3:
Fragment4 fragment4=new Fragment4();
ft.replace(R.id.content_frame, fragment4);
Bundle b3 = new Bundle();
b3.putString("name",myfriendname[position]);
b3.putInt("photo",photo[position]);
fragment4.setArguments(b3);
break;
}
ft.commit();
listview.setItemChecked(position, true);
setTitle(myfriendname[position]);
drawlayout.closeDrawer(listview);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId()==android.R.id.home)
{
if(drawlayout.isDrawerOpen(listview))
{
drawlayout.closeDrawer(listview);
}
else {
drawlayout.openDrawer(listview);
}
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getSupportMenuInflater();
menuInflater.inflate(R.menu.actionbar_sort_menu, menu);
return super.onCreateOptionsMenu(menu);
}
}
This is not a bug. It is designed to be like this and it is not related to all files you have posted here but your menu file named actionbar_sort_menu. In this file you are having probably something like this:
<item
android:id="@+id/menu_delete"
android:orderInCategory="100"
android:showAsAction="ifRoom|withText"
android:title="@string/menu_delete"
android:icon="@drawable/ic_white_trash"/>
And all you need to do is to not use title. But if you want to see a description for that item, so write something for it.