Frage

I have a class that takes a fragment object in; and that fragment object contains several seekbars.

In order to take the value of the seekbar from the fragment I instantiated the fragmentObject in my main activity and called fragmentObject.seekBar.getProgress();

However; this doesn't return anything?

Main Activity code:

//loops repeatedly
public void loop() throws ConnectionLostException, InterruptedException {

    float f = ((float)fragmentObject.pwm1Seek.getProgress()/330);

    }
}

Relevant Fragment Code:

    package com.example.ioiorun;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SeekBar;
import android.widget.Switch;
import android.widget.TextView;
import android.support.v4.app.Fragment;

public class fragmentExample extends Fragment {
    String TAG;
    // Declare all the UI Variables
    View fragmentView;

        SeekBar pwm1Seek;


    public View onCreateView(LayoutInflater viewInflation, ViewGroup container,
            Bundle SavedInstantState) {

        fragmentView = viewInflation.inflate(R.layout.pwmfragment_page,
                container, false);
        pwm1Seek = (SeekBar) pwmFragmentView.findViewById(R.id.pwm1SeekBar);

        pwm1Seek.setMax(330);


        pwm1Seek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress,
                    boolean fromUser) {
                // TODO Auto-generated method stub
                float f = (float)progress/100;
                pwm1Voltage.setText("Voltage: " + String.valueOf(f));
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub
            }
        });


        _mainactivity.setCurrentPWMFragment(this);

        return fragmentView;
    }

    public View getFragmentView() {
        return fragmentView;
    }

    public void setFragmentView(View fragmentView) {
        this.fragmentView = fragmentView;
    }
}
War es hilfreich?

Lösung

I found my error; I was incorrectly instantiating my fragment objects within my other class.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top