将 ProgressDialog 添加到 NavigationDrawer
Add a ProgressDialog into a NavigationDrawer
我的代码做了不同类型的事情,但没有完全符合我的要求。
问题 -
当应用程序启动时,主页不会显示。
选择项目时,侧栏 (NavigationDrawer)
不会隐藏。它不会显示下一个片段,直到我在横向栏外单击。
请帮忙:(
import java.util.ArrayList;
import org.json.JSONException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import com.paypal.android.sdk.payments.PayPalAuthorization;
import com.paypal.android.sdk.payments.PayPalConfiguration;
import com.paypal.android.sdk.payments.PayPalService;
import com.paypal.android.sdk.payments.PaymentActivity;
import com.paypal.android.sdk.payments.PaymentConfirmation;
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
@SuppressLint("NewApi")
public class MainActivity extends Activity {
//paypal
public static final String TAG = "Inscripción Evento";
public static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_SANDBOX;
public static final String CONFIG_CLIENT_ID = "AU3fdxNPtXe8cz2lbvcBYt7jvJ12uA9CeYpQBNZgfHy5CvxCS6SDDGHIp7nqbBMNksrQh9u0zL3zXRnM";
public static final int REQUEST_CODE_PAYMENT = 1;
public static final int REQUEST_CODE_FUTURE_PAYMENT = 2;
public static final int REQUEST_CODE_PROFILE_SHARING = 3;
public static PayPalConfiguration config = new PayPalConfiguration().environment(CONFIG_ENVIRONMENT).clientId(CONFIG_CLIENT_ID).languageOrLocale("es_MX").merchantName("iESNAJ").merchantPrivacyPolicyUri(Uri.parse("https://www.example.com/privacy")).merchantUserAgreementUri(Uri.parse("https://www.example.com/legal"));
//fin paypal
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
// nav drawer title
private CharSequence mDrawerTitle;
// used to store app title
private CharSequence mTitle;
TextView BarTitulo;
// slide menu items
private String[] navMenuTitles;
private TypedArray navMenuIcons;
private ArrayList<NavDrawerItem> navDrawerItems;
private NavDrawerListAdapter adapter;
static String URL = "";
iGuepardosVariables variables = new iGuepardosVariables();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getActionBar().setCustomView(R.layout.iguepardos_action_bar);
getActionBar().setDisplayShowHomeEnabled(true);
getActionBar().setHomeButtonEnabled(true);
getActionBar().setIcon(R.drawable.space);
//getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.header));
getActionBar().setDisplayHomeAsUpEnabled(true);//agregado
((ActionBar) getActionBar()).setHomeButtonEnabled(true);
ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setMessage("Loading...");
progressDialog.setCancelable(false);
try
{
int titleId = getResources().getIdentifier("action_bar_title", "id", "android");
TextView yourTextView = (TextView) findViewById(titleId);
yourTextView.setTextColor(getResources().getColor(R.color.list_item_title));
yourTextView.setTextSize(13);
yourTextView.setGravity(Gravity.CENTER_HORIZONTAL);//agregado
yourTextView.setVisibility(View.INVISIBLE);
}
catch (Exception e) {}
CreaMenu();
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.menu01, //nav menu toggle icon
R.string.app_name, // nav drawer open - description for accessibility
R.string.app_name // nav drawer close - description for accessibility
) {
public void onDrawerClosed(View view) {
getActionBar().setTitle(mTitle);
// calling onPrepareOptionsMenu() to show action bar icons
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
//getActionBar().setTitle(mDrawerTitle);
// calling onPrepareOptionsMenu() to hide action bar icons
invalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
if (savedInstanceState == null) {
// on first time display view for first nav item
if (savedInstanceState == null) {
if (navDrawerItems.get(0).getTitle() != null & navDrawerItems.get(1).getTitle() != null) {
}
else if (navDrawerItems.get(0).getTitle() != null) {
} else {
}
}
}
}
private void CreaMenu()
{
this.VerificaPerfilLocal();
mTitle = mDrawerTitle = getTitle();
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.list_slidermenu);
//Declaramos el header el caul sera el layout de header.xml
//View header = getLayoutInflater().inflate(R.layout.header, null);
//Establecemos header
//mDrawerList.addHeaderView(header);
// load slide menu items
navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);
// nav drawer icons from resources
navMenuIcons = getResources().obtainTypedArray(R.array.nav_drawer_icons);
navDrawerItems = new ArrayList<NavDrawerItem>();
// adding nav drawer items to array
//Perfil
if(variables.usuario.equals("")){
navDrawerItems.add(new NavDrawerItem(R.id.icon, "Usuario", "No ha iniciado sesión", null, null, 0, false));
}
else
{
navDrawerItems.add(new NavDrawerItem(R.id.icon, "Usuario", variables.usuario, null, null, 0, false));
}
// Home
navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1)));
// Calendario de Eventos
navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -2)));
// Resultados
navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1)));
// Contacto
navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1)));
// Registra tu Evento
navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons.getResourceId(4, -1)));
// Onclick MX
navDrawerItems.add(new NavDrawerItem(navMenuTitles[5], navMenuIcons.getResourceId(5, -1)));
// Iniciar sesión
if(variables.usuario.equals(""))
navDrawerItems.add(new NavDrawerItem(navMenuTitles[6], navMenuIcons.getResourceId(6, -1)));
else
navDrawerItems.add(new NavDrawerItem("Cerrar Sesión", navMenuIcons.getResourceId(6, -1)));
// Recycle the typed array
navMenuIcons.recycle();
mDrawerList.setOnItemClickListener((OnItemClickListener) new SlideMenuClickListener());
// setting the nav drawer list adapter
adapter = new NavDrawerListAdapter(getApplicationContext(), navDrawerItems);
mDrawerList.setAdapter(adapter);
}
/**
* Slide menu item click listener
* */
private class SlideMenuClickListener implements OnItemClickListener {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final int thePos = position;
mDrawerLayout.setDrawerListener( new DrawerLayout.SimpleDrawerListener(){
@Override
public void onDrawerClosed(View drawerView) {
boolean wasChecked = !mDrawerList.isItemChecked(thePos);
//Toast.makeText(homeActivity, "Item pulsado: " + wasChecked, Toast.LENGTH_SHORT).show();
mDrawerList.setItemChecked(thePos, !wasChecked);
Fragment fragment = null;
switch (thePos) {
/*case 0:
fragment = new HomeFragment();
break;*/
case 1:
fragment = new HomeFragment();
break;
case 2:
fragment = new CalendarioFragment();
break;
case 5:
fragment = new ContactoFragment();
break;
case 6:
fragment = new OnclickFragment();
break;
default:
break;
}
if (fragment != null) {
try{
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit();
// update selected item and title, then close the drawer
mDrawerList.setItemChecked(thePos, true);
mDrawerList.setSelection(thePos);
setTitle(navMenuTitles[thePos]);
mDrawerLayout.closeDrawer(mDrawerList);
}
catch(Exception E)
{
Log.e("MainActivity", "Error in creating fragment");
}
}
else {
// error in creating fragment
Log.e("MainActivity", "Error in creating fragment");
}
}
});
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// toggle nav drawer on selecting action bar app icon/title
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Handle action bar actions click
switch (item.getItemId()) {
case R.id.action_settings:
return true;
default:
return super.onOptionsItemSelected(item);
}
}
/* *
* Called when invalidateOptionsMenu() is triggered
*/
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
// if nav drawer is opened, hide the action items
boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
menu.findItem(R.id.action_settings).setVisible(!drawerOpen);
CreaMenu();
return super.onPrepareOptionsMenu(menu);
}
/**
* Diplaying fragment view for selected nav drawer list item
* */
@Override
public void setTitle(CharSequence title) {
mTitle = title;
getActionBar().setTitle(mTitle);
}
/**
* When using the ActionBarDrawerToggle, you must call it during
* onPostCreate() and onConfigurationChanged()...
*/
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Pass any configuration change to the drawer toggls
mDrawerToggle.onConfigurationChanged(newConfig);
}
private void sendAuthorizationToServer(PayPalAuthorization authorization) {
/**
* TODO: Send the authorization response to your server, where it can
* exchange the authorization code for OAuth access and refresh tokens.
*
* Your server must then store these tokens, so that your server code
* can execute payments for this user in the future.
*
* A more complete example that includes the required app-server to
* PayPal-server integration is available from
* https://github.com/paypal/rest-api-sdk-python/tree/master/samples/mobile_backend
*/
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == MainActivity.REQUEST_CODE_PAYMENT) {
if (resultCode == Activity.RESULT_OK) {
PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirm != null) {
try {
Log.i(MainActivity.TAG, confirm.toJSONObject().toString(4));
Log.i(MainActivity.TAG, confirm.getPayment().toJSONObject().toString(4));
/**
* TODO: send 'confirm' (and possibly confirm.getPayment() to your server for verification
* or consent completion.
* See https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/
* for more details.
*
* For sample mobile backend interactions, see
* https://github.com/paypal/rest-api-sdk-python/tree/master/samples/mobile_backend
*/
Fragment f = MainActivity.this.getFragmentManager().findFragmentById(R.id.frame_container);
if (f instanceof EventoFragment)
EventoFragment.SendEmailConfirmation(variables.direccionIpWS);
Toast.makeText(getApplicationContext(), "Se ha enviado un e-mail con la confirmación de la inscripción.", Toast.LENGTH_LONG).show();
//Toast.makeText(getApplicationContext(), "PaymentConfirmation info received from PayPal", Toast.LENGTH_LONG).show();
} catch (JSONException e) {
Log.e(MainActivity.TAG, "an extremely unlikely failure occurred: ", e);
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
Log.i(MainActivity.TAG, "The user canceled.");
} else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
Log.i(MainActivity.TAG,"An invalid Payment or PayPalConfiguration was submitted. Please see the docs.");
}
}
}
@Override
public void onDestroy() {
// Stop service when done
MainActivity.this.stopService(new Intent(MainActivity.this, PayPalService.class));
super.onDestroy();
}
private void VerificaPerfilLocal()
{
try
{
SharedPreferences preferencias;
preferencias = getSharedPreferences("loginGuepardos", Context.MODE_PRIVATE);
if(variables.usuario.toString().equals("") && preferencias.contains("ID_EMAIL"))
{
variables.usuario = preferencias.getString("ID_EMAIL", null);
}
}
catch(Exception e) {}
}
}
如果您知道哪里出了问题,请帮我解决这个问题。
对于初学者,试试这个,当你点击一个项目时它应该隐藏横向栏:
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.menu01, //nav menu toggle icon
R.string.app_name, // nav drawer open - description for accessibility
R.string.app_name // nav drawer close - description for accessibility
) {
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
getActionBar().setTitle(mTitle);
// calling onPrepareOptionsMenu() to show action bar icons
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
//getActionBar().setTitle(mDrawerTitle);
// calling onPrepareOptionsMenu() to hide action bar icons
invalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
我现在会更深入地研究您的问题。
我的代码做了不同类型的事情,但没有完全符合我的要求。
问题 -
当应用程序启动时,主页不会显示。
选择项目时,侧栏 (NavigationDrawer)
不会隐藏。它不会显示下一个片段,直到我在横向栏外单击。
请帮忙:(
import java.util.ArrayList;
import org.json.JSONException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import com.paypal.android.sdk.payments.PayPalAuthorization;
import com.paypal.android.sdk.payments.PayPalConfiguration;
import com.paypal.android.sdk.payments.PayPalService;
import com.paypal.android.sdk.payments.PaymentActivity;
import com.paypal.android.sdk.payments.PaymentConfirmation;
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
@SuppressLint("NewApi")
public class MainActivity extends Activity {
//paypal
public static final String TAG = "Inscripción Evento";
public static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_SANDBOX;
public static final String CONFIG_CLIENT_ID = "AU3fdxNPtXe8cz2lbvcBYt7jvJ12uA9CeYpQBNZgfHy5CvxCS6SDDGHIp7nqbBMNksrQh9u0zL3zXRnM";
public static final int REQUEST_CODE_PAYMENT = 1;
public static final int REQUEST_CODE_FUTURE_PAYMENT = 2;
public static final int REQUEST_CODE_PROFILE_SHARING = 3;
public static PayPalConfiguration config = new PayPalConfiguration().environment(CONFIG_ENVIRONMENT).clientId(CONFIG_CLIENT_ID).languageOrLocale("es_MX").merchantName("iESNAJ").merchantPrivacyPolicyUri(Uri.parse("https://www.example.com/privacy")).merchantUserAgreementUri(Uri.parse("https://www.example.com/legal"));
//fin paypal
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
// nav drawer title
private CharSequence mDrawerTitle;
// used to store app title
private CharSequence mTitle;
TextView BarTitulo;
// slide menu items
private String[] navMenuTitles;
private TypedArray navMenuIcons;
private ArrayList<NavDrawerItem> navDrawerItems;
private NavDrawerListAdapter adapter;
static String URL = "";
iGuepardosVariables variables = new iGuepardosVariables();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getActionBar().setCustomView(R.layout.iguepardos_action_bar);
getActionBar().setDisplayShowHomeEnabled(true);
getActionBar().setHomeButtonEnabled(true);
getActionBar().setIcon(R.drawable.space);
//getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.header));
getActionBar().setDisplayHomeAsUpEnabled(true);//agregado
((ActionBar) getActionBar()).setHomeButtonEnabled(true);
ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setMessage("Loading...");
progressDialog.setCancelable(false);
try
{
int titleId = getResources().getIdentifier("action_bar_title", "id", "android");
TextView yourTextView = (TextView) findViewById(titleId);
yourTextView.setTextColor(getResources().getColor(R.color.list_item_title));
yourTextView.setTextSize(13);
yourTextView.setGravity(Gravity.CENTER_HORIZONTAL);//agregado
yourTextView.setVisibility(View.INVISIBLE);
}
catch (Exception e) {}
CreaMenu();
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.menu01, //nav menu toggle icon
R.string.app_name, // nav drawer open - description for accessibility
R.string.app_name // nav drawer close - description for accessibility
) {
public void onDrawerClosed(View view) {
getActionBar().setTitle(mTitle);
// calling onPrepareOptionsMenu() to show action bar icons
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
//getActionBar().setTitle(mDrawerTitle);
// calling onPrepareOptionsMenu() to hide action bar icons
invalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
if (savedInstanceState == null) {
// on first time display view for first nav item
if (savedInstanceState == null) {
if (navDrawerItems.get(0).getTitle() != null & navDrawerItems.get(1).getTitle() != null) {
}
else if (navDrawerItems.get(0).getTitle() != null) {
} else {
}
}
}
}
private void CreaMenu()
{
this.VerificaPerfilLocal();
mTitle = mDrawerTitle = getTitle();
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.list_slidermenu);
//Declaramos el header el caul sera el layout de header.xml
//View header = getLayoutInflater().inflate(R.layout.header, null);
//Establecemos header
//mDrawerList.addHeaderView(header);
// load slide menu items
navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);
// nav drawer icons from resources
navMenuIcons = getResources().obtainTypedArray(R.array.nav_drawer_icons);
navDrawerItems = new ArrayList<NavDrawerItem>();
// adding nav drawer items to array
//Perfil
if(variables.usuario.equals("")){
navDrawerItems.add(new NavDrawerItem(R.id.icon, "Usuario", "No ha iniciado sesión", null, null, 0, false));
}
else
{
navDrawerItems.add(new NavDrawerItem(R.id.icon, "Usuario", variables.usuario, null, null, 0, false));
}
// Home
navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1)));
// Calendario de Eventos
navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -2)));
// Resultados
navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1)));
// Contacto
navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1)));
// Registra tu Evento
navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons.getResourceId(4, -1)));
// Onclick MX
navDrawerItems.add(new NavDrawerItem(navMenuTitles[5], navMenuIcons.getResourceId(5, -1)));
// Iniciar sesión
if(variables.usuario.equals(""))
navDrawerItems.add(new NavDrawerItem(navMenuTitles[6], navMenuIcons.getResourceId(6, -1)));
else
navDrawerItems.add(new NavDrawerItem("Cerrar Sesión", navMenuIcons.getResourceId(6, -1)));
// Recycle the typed array
navMenuIcons.recycle();
mDrawerList.setOnItemClickListener((OnItemClickListener) new SlideMenuClickListener());
// setting the nav drawer list adapter
adapter = new NavDrawerListAdapter(getApplicationContext(), navDrawerItems);
mDrawerList.setAdapter(adapter);
}
/**
* Slide menu item click listener
* */
private class SlideMenuClickListener implements OnItemClickListener {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final int thePos = position;
mDrawerLayout.setDrawerListener( new DrawerLayout.SimpleDrawerListener(){
@Override
public void onDrawerClosed(View drawerView) {
boolean wasChecked = !mDrawerList.isItemChecked(thePos);
//Toast.makeText(homeActivity, "Item pulsado: " + wasChecked, Toast.LENGTH_SHORT).show();
mDrawerList.setItemChecked(thePos, !wasChecked);
Fragment fragment = null;
switch (thePos) {
/*case 0:
fragment = new HomeFragment();
break;*/
case 1:
fragment = new HomeFragment();
break;
case 2:
fragment = new CalendarioFragment();
break;
case 5:
fragment = new ContactoFragment();
break;
case 6:
fragment = new OnclickFragment();
break;
default:
break;
}
if (fragment != null) {
try{
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit();
// update selected item and title, then close the drawer
mDrawerList.setItemChecked(thePos, true);
mDrawerList.setSelection(thePos);
setTitle(navMenuTitles[thePos]);
mDrawerLayout.closeDrawer(mDrawerList);
}
catch(Exception E)
{
Log.e("MainActivity", "Error in creating fragment");
}
}
else {
// error in creating fragment
Log.e("MainActivity", "Error in creating fragment");
}
}
});
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// toggle nav drawer on selecting action bar app icon/title
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Handle action bar actions click
switch (item.getItemId()) {
case R.id.action_settings:
return true;
default:
return super.onOptionsItemSelected(item);
}
}
/* *
* Called when invalidateOptionsMenu() is triggered
*/
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
// if nav drawer is opened, hide the action items
boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
menu.findItem(R.id.action_settings).setVisible(!drawerOpen);
CreaMenu();
return super.onPrepareOptionsMenu(menu);
}
/**
* Diplaying fragment view for selected nav drawer list item
* */
@Override
public void setTitle(CharSequence title) {
mTitle = title;
getActionBar().setTitle(mTitle);
}
/**
* When using the ActionBarDrawerToggle, you must call it during
* onPostCreate() and onConfigurationChanged()...
*/
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Pass any configuration change to the drawer toggls
mDrawerToggle.onConfigurationChanged(newConfig);
}
private void sendAuthorizationToServer(PayPalAuthorization authorization) {
/**
* TODO: Send the authorization response to your server, where it can
* exchange the authorization code for OAuth access and refresh tokens.
*
* Your server must then store these tokens, so that your server code
* can execute payments for this user in the future.
*
* A more complete example that includes the required app-server to
* PayPal-server integration is available from
* https://github.com/paypal/rest-api-sdk-python/tree/master/samples/mobile_backend
*/
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == MainActivity.REQUEST_CODE_PAYMENT) {
if (resultCode == Activity.RESULT_OK) {
PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirm != null) {
try {
Log.i(MainActivity.TAG, confirm.toJSONObject().toString(4));
Log.i(MainActivity.TAG, confirm.getPayment().toJSONObject().toString(4));
/**
* TODO: send 'confirm' (and possibly confirm.getPayment() to your server for verification
* or consent completion.
* See https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/
* for more details.
*
* For sample mobile backend interactions, see
* https://github.com/paypal/rest-api-sdk-python/tree/master/samples/mobile_backend
*/
Fragment f = MainActivity.this.getFragmentManager().findFragmentById(R.id.frame_container);
if (f instanceof EventoFragment)
EventoFragment.SendEmailConfirmation(variables.direccionIpWS);
Toast.makeText(getApplicationContext(), "Se ha enviado un e-mail con la confirmación de la inscripción.", Toast.LENGTH_LONG).show();
//Toast.makeText(getApplicationContext(), "PaymentConfirmation info received from PayPal", Toast.LENGTH_LONG).show();
} catch (JSONException e) {
Log.e(MainActivity.TAG, "an extremely unlikely failure occurred: ", e);
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
Log.i(MainActivity.TAG, "The user canceled.");
} else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
Log.i(MainActivity.TAG,"An invalid Payment or PayPalConfiguration was submitted. Please see the docs.");
}
}
}
@Override
public void onDestroy() {
// Stop service when done
MainActivity.this.stopService(new Intent(MainActivity.this, PayPalService.class));
super.onDestroy();
}
private void VerificaPerfilLocal()
{
try
{
SharedPreferences preferencias;
preferencias = getSharedPreferences("loginGuepardos", Context.MODE_PRIVATE);
if(variables.usuario.toString().equals("") && preferencias.contains("ID_EMAIL"))
{
variables.usuario = preferencias.getString("ID_EMAIL", null);
}
}
catch(Exception e) {}
}
}
如果您知道哪里出了问题,请帮我解决这个问题。
对于初学者,试试这个,当你点击一个项目时它应该隐藏横向栏:
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.menu01, //nav menu toggle icon
R.string.app_name, // nav drawer open - description for accessibility
R.string.app_name // nav drawer close - description for accessibility
) {
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
getActionBar().setTitle(mTitle);
// calling onPrepareOptionsMenu() to show action bar icons
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
//getActionBar().setTitle(mDrawerTitle);
// calling onPrepareOptionsMenu() to hide action bar icons
invalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
我现在会更深入地研究您的问题。