setOnSeekBarChangeListener 没有反应

setOnSeekBarChangeListener doesn't react

onCreate 找到 "angreiferControl" SeekBar,但 onProgressChanged 方法没有反应。

我的应用确实显示了三个片段。这里唯一的问题是 setOnSeekBarChangeListener 方法。

package com.example.sascha.dominion;

import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.util.Log;
import android.widget.SeekBar;
import android.widget.TextView;


public class DomintionGen extends FragmentActivity {
    private TabsPagerAdapter mAdapter;
    private ViewPager viewPager=null;
    private SeekBar angreiferControl = null;
    private SeekBar verteidigerControl = null;
    private SeekBar geld1Control = null;
    private SeekBar geld2Control = null;
    private SeekBar geld3Control = null;
    private SeekBar geld4Control = null;
    private SeekBar geld5Control = null;
    private SeekBar geld6Control = null;
    private TextView angreiferText = null;
    private TextView verteidigerText = null;
    private TextView geld1Text = null;
    private TextView geld2Text = null;
    private TextView geld3Text = null;
    private TextView geld4Text = null;
    private TextView geld5Text = null;
    private TextView geld6Text = null;

    public void sendMessage(View view) {
        angreiferControl = (SeekBar) findViewById(R.id.seekBar);
        verteidigerControl = (SeekBar) findViewById(R.id.seekBar2);
        geld1Control = (SeekBar) findViewById(R.id.seekBar3);
        geld2Control = (SeekBar) findViewById(R.id.seekBar4);
        geld3Control = (SeekBar) findViewById(R.id.seekBar5);
        geld4Control = (SeekBar) findViewById(R.id.seekBar6);
        geld5Control = (SeekBar) findViewById(R.id.seekBar7);
        geld6Control = (SeekBar) findViewById(R.id.seekBar8);
        verteidigerText = (TextView) findViewById(R.id.textView);
        angreiferText = (TextView) findViewById(R.id.textView2);
        geld1Text = (TextView) findViewById(R.id.textView3);
        geld2Text = (TextView) findViewById(R.id.textView4);
        geld3Text = (TextView) findViewById(R.id.textView5);
        geld4Text = (TextView) findViewById(R.id.textView6);
        geld5Text = (TextView) findViewById(R.id.textView7);
        geld6Text = (TextView) findViewById(R.id.textView8);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_domintion_gen);

        viewPager = (ViewPager) findViewById(R.id.pager);
        mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
        viewPager.setAdapter(mAdapter);

        angreiferControl = (SeekBar)  findViewById(R.id.seekBar);

            angreiferControl.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
                int progressChanged = 0;

                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                    progressChanged = progress;
                    angreiferText.setText(progress);
                    Log.i("MyActivity", "Ungleich null " + progress);
                     }

                public void onStartTrackingTouch(SeekBar seekBar) {
                    Log.i("MyActivity", "Ungleich null "+progressChanged );

                }

                public void onStopTrackingTouch(SeekBar seekBar) {

                }
            });

    }

}

具体片段:

public class GenFragment2 extends Fragment {

    public GenFragment2() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_2, container, false);

        return rootView;

    }
}

不要使用直接参数。

这对你有帮助

angreiferText.setText(progressChanged);

我解决了!

必须在我的 GenFragment2 中调用 setOnSeekBarListener 方法 class。在 onActivityCreated 方法中。