Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Cant use seekbar within android app(navigation) drawer from a fragment?

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Cant use seekbar within android app(navigation) drawer from a fragment?

    Basically I've created an app drawer and placed a seekbar within it. This app drawer is made up from app_drawer.xml whilst my fragment below is made up from main_activity.xml.

    The issue I'm having is, although the seekbar shows up perfectly and the app drawer pulls in and out as it should, when I drag it nothing happens (By which I mean the textview is NOT updated)

    Even though it should

    Before anyone suggests that the seekbar is the problem, it is part of a listener event which means it is called every-time progress changes. So it won't be destroyed when oncreate finishes.

    - I have attempted to run seekbar normally on the same xml as
    everything else and it works fine.

    The problem is to do with the fact I'm attempting to utilise 2 xml files in the below fashion.


    I was thinking it may have something to do with the parameter ''container''. I also considered it may have something to do with the fact I'm only returning rootView not rootView and rootView2.


    How do I get this to work correctly?

    My fragment code is below:

         public class MainActivity extends Fragment {
     
                    @Override
                    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                            Bundle savedInstanceState) {
     
                        View rootView = inflater.inflate(R.layout.main_activity, container, false);
                        View rootView2 = inflater.inflate(R.layout.app_drawer, container, false);
     
     
     
               	 final SeekBar sk=(SeekBar) rootView2.findViewById(R.id.seekBar1);  
                 TextView textProgress = (TextView)rootView.findViewById(R.id.TextView01);
     
                      sk.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {   
     
                      public void onProgressChanged(SeekBar bar, int progress,
                      		boolean fromUser) {
     
         textProgress.setText("Progress: "+ String.valueOf(progress));
            }
              		@Override
              		public void onStartTrackingTouch(SeekBar seekBar) {
              			// TODO Auto-generated method stub
     
              		}
     
              		@Override
              		public void onStopTrackingTouch(SeekBar seekBar) {
              			// TODO Auto-generated method stub
     
              		}
                      });
     
                        return rootView;
                    }
                }
    Last edited by User159; March 15th, 2014 at 08:08 PM.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Cant use seekbar within android app(navigation) drawer from a fragment?

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Moved to Android section.

  3. #3
    Junior Member
    Join Date
    Mar 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Cant use seekbar within android app(navigation) drawer from a fragment?

    Do you know of a solution to the above problem?

  4. #4
    Forum VIP
    Join Date
    Jun 2011
    Posts
    317
    My Mood
    Bored
    Thanks
    47
    Thanked 89 Times in 74 Posts
    Blog Entries
    4

    Default Re: Cant use seekbar within android app(navigation) drawer from a fragment?

    Set the attachToRoot parameter of rootView2 to true.

    //View rootView2 = inflater.inflate(R.layout.app_drawer, container, false);
     
    //Change to this:
    View rootView2 = inflater.inflate(R.layout.app_drawer, container, true);

    When attachToRoot is false the layout is inflated but isn't attached to the root layout so it won't fire the event.

  5. #5
    Junior Member
    Join Date
    Mar 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Cant use seekbar within android app(navigation) drawer from a fragment?

    Quote Originally Posted by ChristopherLowe View Post
    Set the attachToRoot parameter of rootView2 to true.

    //View rootView2 = inflater.inflate(R.layout.app_drawer, container, false);
     
    //Change to this:
    View rootView2 = inflater.inflate(R.layout.app_drawer, container, true);

    When attachToRoot is false the layout is inflated but isn't attached to the root layout so it won't fire the event.
    I've tried that and still nothing hapens when I move the seekbar toggle

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Cant use seekbar within android app(navigation) drawer from a fragment?

    Can you put the project files in a zip file and attach it here for testing?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Mar 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Cant use seekbar within android app(navigation) drawer from a fragment?

    Quote Originally Posted by Norm View Post
    Can you put the project files in a zip file and attach it here for testing

    Yes, I'll pm you both a mediafire link. A fix to this problem would be amazing!!


    I've sent you both a link to the project files. ( let me know if you've received it)

    thanks for taking the time btw, it is appreciated
    Last edited by User159; March 15th, 2014 at 08:09 PM.

Similar Threads

  1. Creating an android app.
    By absineo in forum Android Development
    Replies: 3
    Last Post: May 13th, 2014, 05:02 PM
  2. QA for Android app
    By deependeroracle in forum Android Development
    Replies: 1
    Last Post: February 28th, 2014, 10:23 AM
  3. Creating an android app.
    By absineo in forum Java Theory & Questions
    Replies: 1
    Last Post: February 4th, 2014, 09:17 AM
  4. Mobile Navigation System in Android
    By cbayoda23 in forum Android Development
    Replies: 2
    Last Post: July 13th, 2013, 06:43 PM
  5. Android Camera app
    By Yoyo_Guru in forum Android Development
    Replies: 1
    Last Post: July 26th, 2012, 01:47 PM