Updating tabs to new tab fragments

Search This thread

dfwcomputer

Senior Member
Mar 22, 2011
117
45
Brisbane
Hi all,

I had an app that was working about 3 years ago that I decided to update for the latest android sdk.I was using tabs but have decided to update to tab fragments with swipe.The problem I'm having is how to lay out the code.I have updated my app but have a few errors.Specifically the Book Now tab usually has a book now form so people can fill it out and upon clicking submit it sms's it to me.Below is the code for BookNowFragmnet.java.

I should mention that the tab and swipe part works flawlessly.I dont have a logcat because it wont build without removing the code

PHP:
package com.deano.dfw;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.telephony.SmsManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class BookNowFragment extends Fragment implements OnClickListener {
    
    
    Button buttonSubmit;
    EditText edittextPhone;
    EditText editTextProblem;
    
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_booknow, container, false);
        
        buttonSubmit = (Button) rootView.findViewById(R.id.buttonSubmit);
        edittextPhone = (EditText) rootView.findViewById(R.id.edittextPhone);
        editTextProblem = (EditText) rootView.findViewById(R.id.editTextProblem);
        
        buttonSubmit.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) 
            {                
                String phoneNo = edittextPhone.getText().toString();
                String message = editTextProblem.getText().toString();                 
                if (phoneNo.length()>0 && message.length()>0)                
                    sendSMS(phoneNo, message);                
                else
                    Toast.makeText(getBaseContext(), 
                        "Please enter both phone number and message.", 
                        Toast.LENGTH_SHORT).show();
            }
        });
        
        return rootView;
    }
    
    
    
    // ---sends a SMS message to another device---
        private void sendSMS(String phoneNumber, String message) {

            /*
             * PendingIntent pi = PendingIntent.getActivity(this, 0, new
             * Intent(this, test.class), 0); SmsManager sms =
             * SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null,
             * message, pi, null);
             */

            String SENT = "SMS_SENT";
            // String DELIVERED = "SMS_DELIVERED";

            PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(
                    SENT), 0);

            /*
             * PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new
             * Intent(DELIVERED), 0);
             */

            // ---when the SMS has been sent---
            registerReceiver(new BroadcastReceiver() {

                @Override
                public void onReceive(Context arg0, Intent arg1) {
                    switch (getResultCode()) {
                    case Activity.RESULT_OK:
                        Toast.makeText(getBaseContext(), "Message Sent",
                                Toast.LENGTH_SHORT).show();
                        break;

                    case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                        Toast.makeText(getBaseContext(), "Generic failure",
                                Toast.LENGTH_SHORT).show();
                        break;

                    case SmsManager.RESULT_ERROR_NO_SERVICE:
                        Toast.makeText(getBaseContext(), "No service",
                                Toast.LENGTH_SHORT).show();
                        break;

                    case SmsManager.RESULT_ERROR_NULL_PDU:
                        Toast.makeText(getBaseContext(), "Null PDU",
                                Toast.LENGTH_SHORT).show();
                        break;

                    case SmsManager.RESULT_ERROR_RADIO_OFF:
                        Toast.makeText(getBaseContext(), "Radio off",
                                Toast.LENGTH_SHORT).show();
                        break;
                    }
                }
            }, new IntentFilter(SENT));

            SmsManager sms = SmsManager.getDefault();

            sms.sendTextMessage(phoneNumber, null, message, sentPI, null);

        }
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        
    }

}


The problem areas are as follows;


1. getBaseContext has the error "The method getBaseContext is undefined for the type new View.OnClickListener"
PHP:
Toast.makeText(getBaseContext(), 
                        "Please enter both phone number and message.", 
                        Toast.LENGTH_SHORT).show();

2. getBroadcast has the error "The method getBroadcast(Context, int, Intent, int) in the type PendingIntent is not applicable for the arguments (BookNowFragment, int, Intent, int)"
PHP:
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0);

3.registerReceiver has the error "The method registerReceiver(new BroadcastReceiver(){}, IntentFilter) is undefined for the type BookNowFragment"
PHP:
// ---when the SMS has been sent---
    registerReceiver(new BroadcastReceiver() {

4. all of the getBaseContext under the following have the error "The method getBaseContext() is undefined for the type new BroadcastReceiver"
PHP:
public void onReceive(Context arg0, Intent arg1) {
                    switch (getResultCode()) {
                    case Activity.RESULT_OK:
                        Toast.makeText(getBaseContext(), "Message Sent",
                                Toast.LENGTH_SHORT).show();
                        break;

                    case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                        Toast.makeText(getBaseContext(), "Generic failure",
                                Toast.LENGTH_SHORT).show();
                        break;

                    case SmsManager.RESULT_ERROR_NO_SERVICE:
                        Toast.makeText(getBaseContext(), "No service",
                                Toast.LENGTH_SHORT).show();
                        break;

                    case SmsManager.RESULT_ERROR_NULL_PDU:
                        Toast.makeText(getBaseContext(), "Null PDU",
                                Toast.LENGTH_SHORT).show();
                        break;

                    case SmsManager.RESULT_ERROR_RADIO_OFF:
                        Toast.makeText(getBaseContext(), "Radio off",
                                Toast.LENGTH_SHORT).show();
                        break;
                    }
                }
            }, new IntentFilter(SENT));


any help would be appreciated I have searched for the last two days trying different things.
 

deanwray

Senior Member
Apr 2, 2006
1,145
427
www.deanwray.co.uk
1. getBaseContext has the error "The method getBaseContext is undefined for the type new View.OnClickListener"
PHP:
Toast.makeText(getBaseContext(), 
                        "Please enter both phone number and message.", 
                        Toast.LENGTH_SHORT).show();

So you are asking for the method "getBaseContext" within an onClickListener... it does not have a method called that... like it's telling you it's undefined
It would probably be a better idea to use application context either by direct use of getApplicationContext or by a "final" reference maybe...


2. getBroadcast has the error "The method getBroadcast(Context, int, Intent, int) in the type PendingIntent is not applicable for the arguments (BookNowFragment, int, Intent, int)"
PHP:
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0);

BookNowFragment is not extended from the base type of Context that is expected in the arguments.


3.registerReceiver has the error "The method registerReceiver(new BroadcastReceiver(){}, IntentFilter) is undefined for the type BookNowFragment"
PHP:
// ---when the SMS has been sent---
    registerReceiver(new BroadcastReceiver() {


4. all of the getBaseContext under the following have the error "The method getBaseContext() is undefined for the type new BroadcastReceiver"
PHP:
public void onReceive(Context arg0, Intent arg1) {
                    switch (getResultCode()) {
                    case Activity.RESULT_OK:
                        Toast.makeText(getBaseContext(), "Message Sent",
                                Toast.LENGTH_SHORT).show();
                        break;

                    case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                        Toast.makeText(getBaseContext(), "Generic failure",
                                Toast.LENGTH_SHORT).show();
                        break;

                    case SmsManager.RESULT_ERROR_NO_SERVICE:
                        Toast.makeText(getBaseContext(), "No service",
                                Toast.LENGTH_SHORT).show();
                        break;

                    case SmsManager.RESULT_ERROR_NULL_PDU:
                        Toast.makeText(getBaseContext(), "Null PDU",
                                Toast.LENGTH_SHORT).show();
                        break;

                    case SmsManager.RESULT_ERROR_RADIO_OFF:
                        Toast.makeText(getBaseContext(), "Radio off",
                                Toast.LENGTH_SHORT).show();
                        break;
                    }
                }
            }, new IntentFilter(SENT));


any help would be appreciated I have searched for the last two days trying different things.


Actually the last to are just repeats of the previous really... I'm guessing here but it seems you may have skipped ahead of where you should be in a learning sense.. cause it seems to be like your running without being knowing how to jog kinda thing. Not attempting to be condescending, just I'm a trainer and always attempt to point this stuff out when I see it :)

Maybe go back and do some of the basics again, and include fragments etc
 

dfwcomputer

Senior Member
Mar 22, 2011
117
45
Brisbane
thanks, Im well aware i'm running before im born :) but this is the only app I intend to write as it's specifically for my business.
 

deanwray

Senior Member
Apr 2, 2006
1,145
427
www.deanwray.co.uk
thanks, Im well aware i'm running before im born :) but this is the only app I intend to write as it's specifically for my business.

hmmm, well if thats all thats wrong with it, all I could offer is for you to send me the packaged src+res and I will have a look... if it takes less than 20 min to fix and get running I have no problem fixing it for you. If it doesn't and maybe takes longer then I may have to leave it. Should be quick though, up to you

But with the info I gave you should be able to fix those 4 issues...if not hit me up on hangouts and will talk you though it
 
Last edited:
  • Like
Reactions: dfwcomputer

dfwcomputer

Senior Member
Mar 22, 2011
117
45
Brisbane
thanks m8.Ill play around today but if I cant figure it out I might get you to have a look if time permits.I develop in eclipse.Is it a matter of just zipping up the project folder?
 

deanwray

Senior Member
Apr 2, 2006
1,145
427
www.deanwray.co.uk
thanks m8.Ill play around today but if I cant figure it out I might get you to have a look if time permits.I develop in eclipse.Is it a matter of just zipping up the project folder?

Yeah, just zip the project.

But like I say just get a reference to the activity to use as the "context" part of the argument, either where you need it or as a final reference or member variable

so getActivity()

or memberVar

Context mContext = null;
(in onCreate) mContext = getActivity();


or as final

final Context c = getActivity();
 
  • Like
Reactions: dfwcomputer

dfwcomputer

Senior Member
Mar 22, 2011
117
45
Brisbane
Yeah, just zip the project.

But like I say just get a reference to the activity to use as the "context" part of the argument, either where you need it or as a final reference or member variable

so getActivity()

or memberVar

Context mContext = null;
(in onCreate) mContext = getActivity();


or as final

final Context c = getActivity();

lol now I have less faith ill be fixing it..... Ill let you know thanks again
 

dfwcomputer

Senior Member
Mar 22, 2011
117
45
Brisbane
Thanks again, I apreciate it.I have changed the personal info and posted the working code here incase someone else has a similar issue.

PHP:
package com.deano.dfw;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.telephony.SmsManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class BookNowFragment extends Fragment implements OnClickListener {
    
    
    Button buttonSubmit;
    EditText edittextPhone;
    EditText editTextProblem;
    
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        final View rootView = inflater.inflate(R.layout.fragment_booknow, container, false);
        
        buttonSubmit = (Button) rootView.findViewById(R.id.buttonSubmit);
        //edittextPhone = (EditText) rootView.findViewById(R.id.edittextPhone);
        //editTextProblem = (EditText) rootView.findViewById(R.id.editTextProblem);
        
        buttonSubmit.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) 
            {                
                String strPhoneNo = "0000000000";
                TextView txtName = (TextView) rootView.findViewById(R.id.edittextName);
                TextView txtPhone = (TextView) rootView.findViewById(R.id.edittextPhone);
                TextView txtProblem = (TextView) rootView.findViewById(R.id.editTextProblem);
                String strName = "Name: " + txtName.getText().toString();
                String strPhone = "Phone: " + txtPhone.getText().toString();
                String strProblem = "Problem: "
                        + txtProblem.getText().toString();
                String strMessage = strName + "\n" + strPhone + "\n"
                        + strProblem;

                BookNowSMS(strPhoneNo, strMessage);
            }
        });
        
        return rootView;
    }
    
    
    
    // ---sends a SMS message to another device---
        private void BookNowSMS(String phoneNumber, String message) {

            /*
             * PendingIntent pi = PendingIntent.getActivity(this, 0, new
             * Intent(this, test.class), 0); SmsManager sms =
             * SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null,
             * message, pi, null);
             */

            String SENT = "SMS_SENT";
            // String DELIVERED = "SMS_DELIVERED";

            PendingIntent sentPI = PendingIntent.getBroadcast(getActivity(), 0, new Intent(
                    SENT), 0);

            /*
             * PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new
             * Intent(DELIVERED), 0);
             */

            // ---when the SMS has been sent---
            getActivity().registerReceiver(new BroadcastReceiver() {

                @Override
                public void onReceive(Context arg0, Intent arg1) {
                    switch (getResultCode()) {
                    case Activity.RESULT_OK:
                        Toast.makeText(getActivity(), "Message Sent",
                                Toast.LENGTH_SHORT).show();
                        break;

                    case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                        Toast.makeText(getActivity(), "Generic failure",
                                Toast.LENGTH_SHORT).show();
                        break;

                    case SmsManager.RESULT_ERROR_NO_SERVICE:
                        Toast.makeText(getActivity(), "No service",
                                Toast.LENGTH_SHORT).show();
                        break;

                    case SmsManager.RESULT_ERROR_NULL_PDU:
                        Toast.makeText(getActivity(), "Null PDU",
                                Toast.LENGTH_SHORT).show();
                        break;

                    case SmsManager.RESULT_ERROR_RADIO_OFF:
                        Toast.makeText(getActivity(), "Radio off",
                                Toast.LENGTH_SHORT).show();
                        break;
                    }
                }
            }, new IntentFilter(SENT));

            SmsManager sms = SmsManager.getDefault();

            sms.sendTextMessage(phoneNumber, null, message, sentPI, null);

        }
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        
    }

}
 

dfwcomputer

Senior Member
Mar 22, 2011
117
45
Brisbane
I forgot the date and time picker arrrrrrrgh :(


I've added the following 2 classes which have no errors and seem to function fine.

DatePickerFragment.java
PHP:
package com.test.dfw;

import java.util.Calendar;

import android.app.DatePickerDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.widget.DatePicker;
import android.widget.TextView;

public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener{

    TextView txtDate;
    
    
     public DatePickerFragment(TextView txtDate) {
        super();
        this.txtDate = txtDate;
    }

    @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            // Use the current date as the default date in the picker
            final Calendar c = Calendar.getInstance();
            int year = c.get(Calendar.YEAR);
            int month = c.get(Calendar.MONTH);
            int day = c.get(Calendar.DAY_OF_MONTH);

            // Create a new instance of DatePickerDialog and return it
            return new DatePickerDialog(getActivity(), this, year, month, day);
        }

        public void onDateSet(DatePicker view, int year, int month, int day) {
            txtDate.setText(new StringBuilder().append(month + 1)
                    .append("-").append(day).append("-").append(year)
                    .append(" "));
        }
    
    
    
}
TimePickerFragment.java
PHP:
package com.test.dfw;

import java.util.Calendar;

import android.app.Dialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.text.format.DateFormat;
import android.widget.TextView;
import android.widget.TimePicker;

public class TimePickerFragment extends DialogFragment  implements TimePickerDialog.OnTimeSetListener{
    
    TextView txtTime;
    
    
    
    public TimePickerFragment(TextView txtTime) {
        super();
        this.txtTime = txtTime;
    }

    @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            // Use the current time as the default values for the picker
            final Calendar c = Calendar.getInstance();
            int hour = c.get(Calendar.HOUR_OF_DAY);
            int minute = c.get(Calendar.MINUTE);

            // Create a new instance of TimePickerDialog and return it
            return new TimePickerDialog(getActivity(), this, hour, minute,
                    DateFormat.is24HourFormat(getActivity()));
        }

        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
           txtTime.setText(hourOfDay+":"+minute);
        }
}

I then updated BookNowFragment.java

PHP:
package com.test.dfw;

import java.util.Calendar;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.telephony.SmsManager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;

public class BookNowFragment extends Fragment implements OnClickListener {

    Button buttonSubmit;
    EditText edittextPhone;
    EditText editTextProblem;
    Button btnChangeDate,btnChangeTime;
    TextView txtDisplayDate,txtDisplayTime;
    DatePicker datePicker;
    TimePicker timePicker;
    
    private int year;
    private int month;
    private int day;
    
    private int hour;
    private int minute;

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        final View rootView = inflater.inflate(R.layout.fragment_booknow,
                container, false);
        
        showCurrentDateOnView();
        showCurrentTimeOnView();

        buttonSubmit = (Button) rootView.findViewById(R.id.buttonSubmit);
        // edittextPhone = (EditText) rootView.findViewById(R.id.edittextPhone);
        // editTextProblem = (EditText)
        // rootView.findViewById(R.id.editTextProblem);

        buttonSubmit.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                String strPhoneNo = "00000000";
                TextView txtName = (TextView) rootView
                        .findViewById(R.id.edittextName);
                TextView txtPhone = (TextView) rootView
                        .findViewById(R.id.edittextPhone);
                //TextView txtDate = (TextView) rootView.findViewById(R.id.date);

                TextView txtProblem = (TextView) rootView
                        .findViewById(R.id.editTextProblem);
                String strName = "Name: " + txtName.getText().toString();
                String strPhone = "Phone: " + txtPhone.getText().toString();
                //String strDate = "Date: " + txtDate.getText().toString();

                String strProblem = "Problem: "
                        + txtProblem.getText().toString();
                String strMessage = strName + "\n" + strPhone + "\n" + strProblem;

                BookNowSMS(strPhoneNo, strMessage);
            }
        });

        return rootView;
    }

    // ---sends a SMS message to another device---
    private void BookNowSMS(String phoneNumber, String message) {

        /*
         * PendingIntent pi = PendingIntent.getActivity(this, 0, new
         * Intent(this, test.class), 0); SmsManager sms =
         * SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null,
         * message, pi, null);
         */

        String SENT = "SMS_SENT";
        // String DELIVERED = "SMS_DELIVERED";

        PendingIntent sentPI = PendingIntent.getBroadcast(getActivity(), 0,
                new Intent(SENT), 0);

        /*
         * PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new
         * Intent(DELIVERED), 0);
         */

        // ---when the SMS has been sent---
        getActivity().registerReceiver(new BroadcastReceiver() {

            @Override
            public void onReceive(Context arg0, Intent arg1) {
                switch (getResultCode()) {
                case Activity.RESULT_OK:
                    Toast.makeText(getActivity(), "Message Sent",
                            Toast.LENGTH_SHORT).show();
                    break;

                case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                    Toast.makeText(getActivity(), "Generic failure",
                            Toast.LENGTH_SHORT).show();
                    break;

                case SmsManager.RESULT_ERROR_NO_SERVICE:
                    Toast.makeText(getActivity(), "No service",
                            Toast.LENGTH_SHORT).show();
                    break;

                case SmsManager.RESULT_ERROR_NULL_PDU:
                    Toast.makeText(getActivity(), "Null PDU",
                            Toast.LENGTH_SHORT).show();
                    break;

                case SmsManager.RESULT_ERROR_RADIO_OFF:
                    Toast.makeText(getActivity(), "Radio off",
                            Toast.LENGTH_SHORT).show();
                    break;
                }
            }
        }, new IntentFilter(SENT));

        SmsManager sms = SmsManager.getDefault();

        sms.sendTextMessage(phoneNumber, null, message, sentPI, null);

    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

    }

    // display current date
            public void showCurrentDateOnView() {
         
                txtDisplayDate = (TextView) findViewById(R.id.txtDate);
                datePicker = (DatePicker) findViewById(R.id.datePicker1);
         
                final Calendar c = Calendar.getInstance();
                year = c.get(Calendar.YEAR);
                month = c.get(Calendar.MONTH);
                day = c.get(Calendar.DAY_OF_MONTH);
         
                // set current date into textview
                txtDisplayDate.setText(new StringBuilder()
                    // Month is 0 based, just add 1
                    .append(month + 1).append("-").append(day).append("-")
                    .append(year).append(" "));
         
                // set current date into datepicker
                datePicker.init(year, month, day, null);
         
            }

            
            // display current time
            public void showCurrentTimeOnView() {
         
                txtDisplayTime = (TextView) findViewById(R.id.txtTime);
                timePicker = (TimePicker) findViewById(R.id.timePicker1);
         
                final Calendar c = Calendar.getInstance();
                hour = c.get(Calendar.HOUR_OF_DAY);
                minute = c.get(Calendar.MINUTE);
         
                // set current time into textview
                txtDisplayTime.setText(
                            new StringBuilder().append(hour)
                                               .append(":").append(minute));
         
                // set current time into timepicker
                timePicker.setCurrentHour(hour);
                timePicker.setCurrentMinute(minute);
         
            }
            
            
            public void showDatePickerDialog(View v) {
                DialogFragment newFragment = new DatePickerFragment(txtDisplayDate);
                newFragment.show(getSupportFragmentManager(), "datePicker");
            }
            
            public void showTimePickerDialog(View v) {
                DialogFragment newFragment = new TimePickerFragment(txtDisplayTime);
                newFragment.show(getSupportFragmentManager(), "timePicker");
            }
            
            
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.activity_main, menu);
            return true;
        }


}

The problem areas are all under BookNowFragment.java;

1. Under "showCurrentDateOnView" the both findViewById says undefined for the type.I have tried adding rootView but didnt work.

2. Under "showCurrentTimeOnView" both findViewById says undefined for the type.I have tried adding rootView but didnt work.

3. under "showDatePickerDialog" and "showTimePickerDialog" both the getSupportFragmentManager methods show the error "The method getSupportFragmentManager() is undefined for the type BookNowFragment"

4. I also have errors with "onCreateOptionsMenu".I worked out some of them by adding getActivity (see new code below) but it still shows the error "The method onCreateOptionsMenu(Menu) of type BookNowFragment must override or implement a supertype method"

PHP:
@Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getActivity().getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }

Think there simple issues although I'm simple as well so I could be understating it.:p
 

Top Liked Posts

  • There are no posts matching your filters.
  • 1
    thanks, Im well aware i'm running before im born :) but this is the only app I intend to write as it's specifically for my business.

    hmmm, well if thats all thats wrong with it, all I could offer is for you to send me the packaged src+res and I will have a look... if it takes less than 20 min to fix and get running I have no problem fixing it for you. If it doesn't and maybe takes longer then I may have to leave it. Should be quick though, up to you

    But with the info I gave you should be able to fix those 4 issues...if not hit me up on hangouts and will talk you though it
    1
    thanks m8.Ill play around today but if I cant figure it out I might get you to have a look if time permits.I develop in eclipse.Is it a matter of just zipping up the project folder?

    Yeah, just zip the project.

    But like I say just get a reference to the activity to use as the "context" part of the argument, either where you need it or as a final reference or member variable

    so getActivity()

    or memberVar

    Context mContext = null;
    (in onCreate) mContext = getActivity();


    or as final

    final Context c = getActivity();
    1
    sent you a private message m8, because there is some personal info in the app

    fixed and sent private msg with class