FORUMS

Updating tabs to new tab fragments

110 posts
Thanks Meter: 45
 
By dfwcomputer, Senior Member on 30th June 2014, 01:53 AM
Post Reply Subscribe to Thread Email Thread
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 Code:
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 inflaterViewGroup container,
            
Bundle savedInstanceState) {

        
View rootView inflater.inflate(R.layout.fragment_booknowcontainerfalse);
        
        
buttonSubmit = (ButtonrootView.findViewById(R.id.buttonSubmit);
        
edittextPhone = (EditTextrootView.findViewById(R.id.edittextPhone);
        
editTextProblem = (EditTextrootView.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()>&& message.length()>0)                
                    
sendSMS(phoneNomessage);                
                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 phoneNumberString 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(this0, 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 arg0Intent 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(phoneNumbernullmessagesentPInull);

        }
    @
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 Code:
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 Code:
PendingIntent sentPI PendingIntent.getBroadcast(this0, new Intent(SENT), 0); 
3.registerReceiver has the error "The method registerReceiver(new BroadcastReceiver(){}, IntentFilter) is undefined for the type BookNowFragment"
PHP Code:
// ---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 Code:
public void onReceive(Context arg0Intent 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.
 
 
30th June 2014, 02:54 AM |#2  
deanwray's Avatar
Senior Member
Thanks Meter: 429
 
Donate to Me
More
Quote:
Originally Posted by dfwcomputer

1. getBaseContext has the error "The method getBaseContext is undefined for the type new View.OnClickListener"

PHP Code:
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...


Quote:
Originally Posted by dfwcomputer

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 Code:
PendingIntent sentPI PendingIntent.getBroadcast(this0, new Intent(SENT), 0); 

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


Quote:
Originally Posted by dfwcomputer

3.registerReceiver has the error "The method registerReceiver(new BroadcastReceiver(){}, IntentFilter) is undefined for the type BookNowFragment"

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


Quote:
Originally Posted by dfwcomputer

4. all of the getBaseContext under the following have the error "The method getBaseContext() is undefined for the type new BroadcastReceiver"

PHP Code:
public void onReceive(Context arg0Intent 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
30th June 2014, 03:42 AM |#3  
OP Senior Member
Flag Brisbane
Thanks Meter: 45
 
More
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.
30th June 2014, 03:48 AM |#4  
deanwray's Avatar
Senior Member
Thanks Meter: 429
 
Donate to Me
More
Quote:
Originally Posted by dfwcomputer

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 by deanwray; 30th June 2014 at 03:50 AM.
The Following User Says Thank You to deanwray For This Useful Post: [ View ]
30th June 2014, 04:00 AM |#5  
OP Senior Member
Flag Brisbane
Thanks Meter: 45
 
More
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?
30th June 2014, 04:06 AM |#6  
deanwray's Avatar
Senior Member
Thanks Meter: 429
 
Donate to Me
More
Quote:
Originally Posted by dfwcomputer

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();
The Following User Says Thank You to deanwray For This Useful Post: [ View ]
30th June 2014, 04:58 AM |#7  
OP Senior Member
Flag Brisbane
Thanks Meter: 45
 
More
Quote:
Originally Posted by deanwray

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
1st July 2014, 02:41 AM |#8  
OP Senior Member
Flag Brisbane
Thanks Meter: 45
 
More
sent you a private message m8, because there is some personal info in the app
1st July 2014, 05:11 AM |#9  
deanwray's Avatar
Senior Member
Thanks Meter: 429
 
Donate to Me
More
Quote:
Originally Posted by dfwcomputer

sent you a private message m8, because there is some personal info in the app

fixed and sent private msg with class
The Following User Says Thank You to deanwray For This Useful Post: [ View ]
1st July 2014, 05:28 AM |#10  
OP Senior Member
Flag Brisbane
Thanks Meter: 45
 
More
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 Code:
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 inflaterViewGroup container,
            
Bundle savedInstanceState) {

        final 
View rootView inflater.inflate(R.layout.fragment_booknowcontainerfalse);
        
        
buttonSubmit = (ButtonrootView.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 = (TextViewrootView.findViewById(R.id.edittextName);
                
TextView txtPhone = (TextViewrootView.findViewById(R.id.edittextPhone);
                
TextView txtProblem = (TextViewrootView.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(strPhoneNostrMessage);
            }
        });
        
        return 
rootView;
    }
    
    
    
    
// ---sends a SMS message to another device---
        
private void BookNowSMS(String phoneNumberString 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 arg0Intent 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(phoneNumbernullmessagesentPInull);

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


2nd July 2014, 09:07 AM |#11  
OP Senior Member
Flag Brisbane
Thanks Meter: 45
 
More
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 Code:
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(), thisyearmonthday);
        }

        public 
void onDateSet(DatePicker viewint yearint monthint day) {
            
txtDate.setText(new StringBuilder().append(month 1)
                    .
append("-").append(day).append("-").append(year)
                    .
append(" "));
        }
    
    
    

TimePickerFragment.java
PHP Code:
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(), thishourminute,
                    
DateFormat.is24HourFormat(getActivity()));
        }

        public 
void onTimeSet(TimePicker viewint hourOfDayint minute) {
           
txtTime.setText(hourOfDay+":"+minute);
        }

I then updated BookNowFragment.java

PHP Code:
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 inflaterViewGroup container,
            
Bundle savedInstanceState) {

        final 
View rootView inflater.inflate(R.layout.fragment_booknow,
                
containerfalse);
        
        
showCurrentDateOnView();
        
showCurrentTimeOnView();

        
buttonSubmit = (ButtonrootView.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 = (TextViewrootView
                        
.findViewById(R.id.edittextName);
                
TextView txtPhone = (TextViewrootView
                        
.findViewById(R.id.edittextPhone);
                
//TextView txtDate = (TextView) rootView.findViewById(R.id.date);

                
TextView txtProblem = (TextViewrootView
                        
.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(strPhoneNostrMessage);
            }
        });

        return 
rootView;
    }

    
// ---sends a SMS message to another device---
    
private void BookNowSMS(String phoneNumberString 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 arg0Intent 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(phoneNumbernullmessagesentPInull);

    }

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

    
}

    
// display current date
            
public void showCurrentDateOnView() {
         
                
txtDisplayDate = (TextViewfindViewById(R.id.txtDate);
                
datePicker = (DatePickerfindViewById(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(yearmonthdaynull);
         
            }

            
            
// display current time
            
public void showCurrentTimeOnView() {
         
                
txtDisplayTime = (TextViewfindViewById(R.id.txtTime);
                
timePicker = (TimePickerfindViewById(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_mainmenu);
            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 Code:
@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.mainmenu);
            return 
true;
        } 
Think there simple issues although I'm simple as well so I could be understating it.

Read More
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes