Closing Sliding menu onItemClick - android

So, I'm using jfeinstein10 library for my SlidingMenu. It works fine but I'm having a problem to toggle the menu when the user taps in one of the menu options.
I have the MainActivty where the slidingmenu is and a fragment called SampleListFragment where I set the menu options.
What I'm trying to do is call a function from the MainActivity when I click the option. This function should only toggle the menu, but instead I get a NullPointException error.
My MainActivity
public class MainActivity extends BaseActivity implements SlidingActivityBase {
private SlidingMenu menu;
private ImageButton btn_pesquisa;
private ImageButton btn_toggle;
private MakeMateria makeMat = new MakeMateria();
private static final int SCREEN_ORIENTATION_PORTRAIT = 1;
String id_test;
SampleListFragment listFragment = new SampleListFragment();
public MainActivity() {
super(R.string.title_bar_content);
}
public void mainToggle() {
Log.d("1", "" + this);
toggle();
Log.d("2", "" + this);
}
public static Intent newInstance(Activity activity, int pos) {
Intent intent = new Intent(activity, MainActivity.class);
intent.putExtra("pos", pos);
return intent;
}
public void testeEvent(){
Log.d("Funciona","works");
toggle();
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
BitmapDrawable bg = (BitmapDrawable) getResources().getDrawable(
R.drawable.titlebar);
bg.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
getSupportActionBar().setBackgroundDrawable(bg);
BitmapDrawable bgSplit = (BitmapDrawable) getResources()
.getDrawable(R.drawable.titlebar);
bgSplit.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
getSupportActionBar().setSplitBackgroundDrawable(bgSplit);
}
int pos = 0;
if (getIntent().getExtras() != null) {
pos = getIntent().getExtras().getInt("pos");
}
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.abs_layout);
menu = new SlidingMenu(this);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setShadowWidthRes(R.dimen.shadow_width);
menu.setShadowDrawable(R.drawable.shadow);
menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
menu.setFadeDegree(0.35f);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
menu.setBehindScrollScale((float) 1.0);
menu.setMenu(R.layout.menu_frame);
// set the Above View
setContentView(R.layout.content_frame);
getSupportFragmentManager().beginTransaction()
.replace(R.id.content_frame, new MainFragment()).commit();
setSlidingActionBarEnabled(true);
btn_pesquisa = (ImageButton) findViewById(R.id.btnPesquisa);
btn_toggle = (ImageButton) findViewById(R.id.btn_menu);
btn_toggle.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
toggle();
}
});
btn_pesquisa.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(getApplicationContext(),
SearchActivity.class);
//startActivity(intent);
overridePendingTransition(R.anim.view_transition_in_left,
R.anim.view_transition_out_left);
}
});
}
public void getMenu(){
menu.toggle();
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
toggle();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
This part is from my fragment:
#Override
public void onListItemClick(ListView lv, View v, int position, long id) {
Fragment newContent = null;
android.support.v4.app.FragmentTransaction transaction = getFragmentManager().beginTransaction();
switch (position) {
case 0:
Log.d("1", "1");
getFragmentManager().beginTransaction().replace(R.id.content_frame, new MainFragment()).commit();
mainActivity.getMenu();
break;
case 1:
Log.d("2", "2");
toggle();
break;
case 2:
Log.d("3", "3");
toggle();
break;
case 3:
Log.d("4", "4");
toggle();
break;
case 4:
Log.d("5", "5");
toggle();
break;
case 5:
Log.d("6", "6");
toggle();
break;
case 6:
Log.d("7", "7");
toggle();
break;
case 7:
Log.d("8", "8");
toggle();
break;
case 8:
Log.d("9", "9");
toggle();
break;
}
if (newContent != null)
switchFragment(newContent);
}
MainActivity mainActivity is global, and the insance of it I did in the onCreateView.
The NPE points to the lines where I call the function and where I call the toggle inside the function.
Many thanks.

I did this -> Android : Accessing container activity object from fragment using putExtra?
The problem was that I passing a null object, but when I did like this ->
((MainActivity) this.getActivity()).getMenu()
I was able to get the correct value from the object.
#Wenger thanks for the help.

Related

Base Activity for custom ListView menu

I'm new in Android programming. I'm working on an application that have multiple activities. I've created a custom menu with ListView. I would like to put this menu in a base activity to be available in all activities. How should I do this?
Till now, I have something like this:
This is for the button to toggle the menu
menuToggelIcon.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
// Hide layouts if VISIBLE
if(menuLayout.getVisibility() == View.VISIBLE)
{
menuLayout.setVisibility(View.GONE);
}
// Show layouts if they're not VISIBLE
else
{
menuLayout.setVisibility(View.VISIBLE);
}
}
});
And this is for the menu
menuListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String name = menuArray[position];
Context context = getApplicationContext();
switch (name) {
case "CASE1":
Intent case1Intent = new Intent(context, Activity1.class);
startActivity(case1Intent);
break;
case "CASE2":
Intent case2Intent = new Intent(context, Activity2.class);
startActivity(case2Intent);
break;
case "CASE3":
Intent case3Intent = new Intent(context, Activity3.class);
startActivity(case3Intent);
break;
case "CASE4":
Intent case4Intent = new Intent(context, Activity4.class);
startActivity(case4Intent);
break;
case "CASE5":
Intent case5Intent = new Intent(context, Activity5.class);
startActivity(case5Intent);
break;
case "CASE6":
Intent case6Intent = new Intent(context, Activity6.class);
startActivity(case6Intent);
break;
case "CASE7":
Intent case7Intent = new Intent(context, Activity7.class);
startActivity(case7Intent);
break;
default:
break;
}
}
});
Android custom menu
make one BaseActivity class and all activity extends by BasyActivity class.
BaseActivity class define your main things that show all the screen like menu and other thing. for example
public class BaseActivity extends AppCompatActivity {
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.manu_file_name, menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.icon) {
Toast.makeText(getApplicationContext(), "Hello World", 0).show();
}
return super.onOptionsItemSelected(item);
}
}
and this activity extends all other activity.

Make back button returns from an activity to a fragment in Android

I'm developing an Android application and I have a fragment called "More", in this fragment I have such things as "About Us", "Terms and Conditions", that are normal activities. What I want to do is, when I click on the back button inside the, for example, the about us Activity I want to return to the "More" fragment. How can I do that? This is what I have in the aboutUs activity:
The "onBackPressed method was supposed to go back to the fragment once I click on the back button, but it is not working. The application crashes and in the log cat is says "Have you declare the MoreFragment Activity in the manifest?", but I tried to declare and it doesn't work.
public class AboutUs extends BaseActivity {
private ImageView image;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about_us);
image = (ImageView) findViewById(R.id.imageView2);
image.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent launchactivity = new Intent(AboutUs.this, StartScreenActivity.class);
startActivity(launchactivity);
}
});
}
#Override
public void onBackPressed()
{
Intent intent = new Intent(this,MoreFragment.class);
startActivity(intent);
}
}
This is the fragment that calls the Activity:
public class MoreFragment extends Fragment implements View.OnClickListener {
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_more, null, false);
}
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
TextView lbl1 = (TextView) view.findViewById(R.id.lbl1);
TextView lbl2 = (TextView) view.findViewById(R.id.lbl2);
TextView lbl3 = (TextView) view.findViewById(R.id.lbl3);
TextView lbl4 = (TextView) view.findViewById(R.id.lbl4);
TextView lbl5 = (TextView) view.findViewById(R.id.lbl5);
TextView lbl6 = (TextView) view.findViewById(R.id.lbl6);
TextView lbl7 = (TextView) view.findViewById(R.id.lbl7);
TextView lbl8 = (TextView) view.findViewById(R.id.lbl8);
TextView lbl9 = (TextView) view.findViewById(R.id.lbl9);
ImageView imv1 = (ImageView) view.findViewById(R.id.imv1);
ImageView imv2 = (ImageView) view.findViewById(R.id.imv2);
ImageView imv3 = (ImageView) view.findViewById(R.id.imv3);
ImageView imv4 = (ImageView) view.findViewById(R.id.imv4);
ImageView imv5 = (ImageView) view.findViewById(R.id.imv5);
ImageView imv6 = (ImageView) view.findViewById(R.id.imv6);
ImageView imv7 = (ImageView) view.findViewById(R.id.imv7);
ImageView imv8 = (ImageView) view.findViewById(R.id.imv8);
ImageView imv9 = (ImageView) view.findViewById(R.id.imv9);
ImageView imv10 = (ImageView) view.findViewById(R.id.imv10);
TextView btnSignOut = (TextView) view.findViewById(R.id.lbl10);
lbl1.setOnClickListener(this);
lbl2.setOnClickListener(this);
lbl3.setOnClickListener(this);
lbl4.setOnClickListener(this);
lbl5.setOnClickListener(this);
lbl6.setOnClickListener(this);
lbl7.setOnClickListener(this);
lbl8.setOnClickListener(this);
lbl9.setOnClickListener(this);
imv1.setOnClickListener(this);
imv2.setOnClickListener(this);
imv3.setOnClickListener(this);
imv4.setOnClickListener(this);
imv5.setOnClickListener(this);
imv6.setOnClickListener(this);
imv7.setOnClickListener(this);
imv8.setOnClickListener(this);
imv9.setOnClickListener(this);
btnSignOut.setOnClickListener(this);
View view9 = view.findViewById(R.id.view9);
View view8 = view.findViewById(R.id.view8);
if (!PrefernceHelper.getBoolean(getActivity(), Commons.Constants.USERLOGGEDIN)) {
imv8.setVisibility(View.INVISIBLE);
lbl8.setVisibility(View.INVISIBLE);
imv10.setVisibility(View.INVISIBLE);
btnSignOut.setVisibility(View.INVISIBLE);
view9.setVisibility(View.INVISIBLE);
view8.setVisibility(View.INVISIBLE);
}
}
private void callAllMoreScreen(String type, Class<?> className) {
Intent intent = new Intent();
intent.setClass(getActivity(), className);
intent.putExtra(Commons.Constants.LOAD_TYPE_URL, type);
getActivity().startActivity(intent);
}
private void callAllMoreScreen1(Class<?> className) {
Intent intent = new Intent();
intent.setClass(getActivity(), className);
getActivity().startActivity(intent);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.lbl1:
callAllMoreScreen1(AboutUs.class);
break;
case R.id.lbl2:
callAllMoreScreen("contact-us", AllMoreScreenActivity.class);
break;
case R.id.lbl3:
callAllMoreScreen1(TermsConditions.class);
break;
case R.id.lbl4:
callAllMoreScreen1(PrivacyPolicy.class);
break;
case R.id.lbl5:
callAllMoreScreen("faqs", AllMoreScreenActivity.class);
break;
case R.id.lbl6:
callAllMoreScreen("how-it-work", AllMoreScreenActivity.class);
break;
case R.id.lbl7:
callAllMoreScreen("about-foodlebee", AllMoreScreenActivity.class);
break;
case R.id.lbl8:
callAllMoreScreen(" ", PredefinedAddressActivity.class);
break;
case R.id.lbl9:
callAllMoreScreen(" ", TrackyourorderActivity.class);
break;
case R.id.imv1:
callAllMoreScreen1(AboutUs.class);
break;
case R.id.imv2:
callAllMoreScreen("contact-us", AllMoreScreenActivity.class);
break;
case R.id.imv3:
callAllMoreScreen1(TermsConditions.class);
break;
case R.id.imv4:
callAllMoreScreen1(PrivacyPolicy.class);
break;
case R.id.imv5:
callAllMoreScreen("faqs", AllMoreScreenActivity.class);
break;
case R.id.imv6:
callAllMoreScreen("how-it-work", AllMoreScreenActivity.class);
break;
case R.id.imv7:
callAllMoreScreen("about-foodlebee", AllMoreScreenActivity.class);
break;
case R.id.imv8:
callAllMoreScreen(" ", PredefinedAddressActivity.class);
break;
case R.id.imv9:
callAllMoreScreen(" ", TrackyourorderActivity.class);
break;
case R.id.lbl10:
PrefernceHelper.clearAll(getActivity());
callAllMoreScreen("", SignInActivity.class);
getActivity().finish();
break;
}
}
}
And this is the Activity that call the fragment:
public class TabLayoutScreenActivity extends BaseActivity {
private TabLayout tabLayout;
private Bundle bundle;
//Bundle bundle;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab_screen);
tabLayout = (TabLayout) findViewById(R.id.tab_layout);
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar); // actionBarSetUp(true);
// getSupportActionBar().setIcon(R.drawable.small_bee);
getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);
// getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// getSupportActionBar().setIcon(R.drawable.ic_launcher);
viewPager.setAdapter(new SectionPagerAdapter(getSupportFragmentManager()));
tabLayout.setupWithViewPager(viewPager);
ImageView foodlebee = (ImageView) findViewById(R.id.imageView2);
foodlebee.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent launchactivity = new Intent(TabLayoutScreenActivity.this,StartScreenActivity.class);
startActivity(launchactivity);
}
});
// bundle = getIntent().getExtras();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_login, menu);
if (PrefernceHelper.getBoolean(this, Commons.Constants.USERLOGGEDIN)) {
MenuItem item = menu.findItem(R.id.user_login);
item.setVisible(false);
invalidateOptionsMenu();
}
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.user_login) {
intentCall(SignInActivity.class, null, 0);
return true;
} else if (item.getItemId() == R.id.home) {
intentCall(StartScreenActivity.class, null, 0);
finish();
return true;
}
return false;
}
#Override
protected void onStart() {
super.onStart();
bundle = getIntent().getExtras();
int tabPostion = 0;
if (bundle != null)
tabPostion = bundle.getInt(Commons.Constants.TAB_POSITION, 0);
TabLayout.Tab tab = tabLayout.getTabAt(tabPostion);
tab.select();
}
public class SectionPagerAdapter extends FragmentPagerAdapter {
public SectionPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return new ChefFragment();
case 1:
return new OrderFragment();
case 2:
return new BasketFragment();
case 3:
return new MoreFragment();
default:
return new ChefFragment();
}
}
#Override
public int getCount() {
return 4;
}
#Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return "Chefs";
case 1:
return "Orders";
case 2:
return "Cart";
case 3:
return "More";
default:
return "Chef";
}
}
}
}
Just finish() the current activity in onbackpressed hence you will return to the more fragment because the previous activity is already on the back stack. You don't need to launch the previous activity again.
Moreover your code is wrong.. you are trying to launch a fragment which is not possible. This is why this exception is thrown.
Change your code like this :
#Override
public void onBackPressed()
{
finish();
}

How to open fragment class through intent in another activity?

My SlidingScreenActivity code is,
private class SlideMenuClickListener implements
ListView.OnItemClickListener {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// display view for selected nav drawer item
displayView(position);
}
}
public void displayView(int position) {
Fragment fragment = null;
switch (position) {
case 0:
mDrawerLayout.closeDrawer(mDrawerList);
break;
case 1:
fragment=new HomeFragment();
break;
case 2:
fragment=new Mywallet();
break;
case 3:
fragment=new AboutUsFragment();
break;
default:
break;
}
}
if (fragment != null) {
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.frame_container, fragment).commit();
mDrawerList.setItemChecked(position, true);
mDrawerList.setSelection(position);
setTitle(navMenuTitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);
} else {
mDrawerLayout.closeDrawer(mDrawerList);
Log.e("SlidingMainActivity", "Error in creating fragment");
}
}
Another Activity button listener,
btnWallet.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent mIntent=new Intent(this,SlidingScreenActivity.class);
startActivity(mIntent);
}
});
How can i openMyWallet fragment that i have already declared in case 2: in SlidingScreenActivity.class ,when click on button in another activity through Intent?
could anyone help me?
Thanks in advance...
SlidingScreenActivity:
#Override
protected void onStart() {
super.onStart();
displayView(getIntent().getIntExtra("position", 2));
}
Another Activity button listener:
btnWallet.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent mIntent=new Intent(this,SlidingScreenActivity.class);
intent.putExtra("position", 2);
startActivity(mIntent);
}
});

ActionBarActivity back button to fragment

I have problem with the back button in action bar to fragment
my code fragment:
public class Server extends Fragment {
View view;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.activity_server, container, false);
Button server = (Button) view.findViewById(R.id.status);
/** Button Check Status Server **/
server.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent myIntent = new Intent(view.getContext(), ServerStatus.class);
startActivityForResult(myIntent, 0);
getActivity().finish();
}
});
return view;
}
}
my code in activity:
public class ServerStatus extends ActionBarActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_server_status);
}
}
My code in Fragment
#Override
public void onNavigationDrawerItemSelected(int position) {
Fragment objFragment = null;
switch (position) {
case 0:
objFragment = new Account();
break;
case 1:
objFragment = new AllNews();
break;
case 2:
objFragment = new Server();
break;
case 3:
objFragment = new Account();
break;
case 4:
objFragment = new Account();
break;
case 5:
objFragment = new Account();
break;
case 6:
objFragment = new About();
break;
}
// update the main content by replacing fragments
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container,objFragment)
.commit();
}
Every time I click the back button, the program always closes. I already tried to use:
getActionBar().setDisplayHomeAsUpEnabled(true);
and this:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
Can anyone help me to fix my program?
EDIT: Concerning cross-activity-navigation, you should not use startActivityForResult() in that way. Try to use startActivity() instead. If you start an activity for a result, the calling activity waits for the onActivityResult() callback and should not be finished.
In the manifest file you should declare the fragment's activity as parent activity of ServerStatus to enable back navigation. You should not need NavUtils.
If you want to enable fragment navigation within an activity, you have to add your fragment transactions to the backstack:
getFragmentManager().beginTransaction().addToBackStack(null).replace(...).commit();
Then you have to call getFragmentManager().popBackStack() in onOptionsItemSelected() to enable back navigation for the action bar:
#override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
getFragmentManager().popBackStack();
return true;
}
return super.onOptionsItemSelected(item);
}
You may have to override onBackPressed() to enable back navigation for the back button:
#override
public void onBackPressed() {
if (getFragmentManager().getBackStackEntryCount() >= 1) {
getFragmentManager().popBackStack(); // return to previous fragment
}
else {
super.onBackPressed(); // Exit application when no fragment is on the backstack
}
}

onListItemClick within onDialogPositiveClick?

How can I refer to onListItemClick within onDialogPositiveClick? So the page does not open before/while the dialog box opens..Can I literally put onListItemClick in onDialogPositiveClick, or do I have to do something completely different? Here is my code...thanks for all/any help!
public class MainActivity extends ListActivity implements TheDialog.NoticeDialogListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
String[] sites = {"Google", "Amazon", "Ebay" , "Reddit", "SmashingMag", "CCC"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.mylist_item, R.id.textView1, sites);
setListAdapter(adapter);
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
DialogFragment newFragment = new TheDialog();
newFragment.show(getFragmentManager(), "Confirm");
Intent i = null;
switch(position){
case 0:
i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(i); break;
case 1:
i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.amazon.com"));
startActivity(i); break;
case 2:
i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.ebay.com"));
startActivity(i); break;
case 3:
i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.reddit.com"));
startActivity(i); break;
case 4:
i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.smashingmag.com"));
startActivity(i); break;
case 5:
i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.myccc.corning-cc.edu"));
startActivity(i); break;
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public void onDialogPositiveClick(DialogFragment dialog) {
// TODO Auto-generated method stub
}
#Override
public void onDialogNegativeClick(DialogFragment dialog) {
// TODO Auto-generated method stub
}
}
What you can do is not fire intent on list item click and move the switch code to
onDialogPositiveClick(DialogFragment dialog){
Intent i = null;
switch(position){
case 0:
i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(i); break;
case 1:
i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.amazon.com"));
startActivity(i); break;
case 2:
i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.ebay.com"));
startActivity(i); break;
case 3:
i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.reddit.com"));
startActivity(i); break;
case 4:
i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.smashingmag.com"));
startActivity(i); break;
case 5:
i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.myccc.corning-cc.edu"));
startActivity(i); break;
}}
This way user will only go to the next page when positive button is clicked, hope you want this kind of behavior.

Categories

Resources