setOnSeekBarChangeListener没有反应

时间:2015-09-11 07:57:04

标签: android seekbar

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;

    }
}

2 个答案:

答案 0 :(得分:0)

不要使用直接参数。

这会对你有所帮助

angreiferText.setText(progressChanged);

答案 1 :(得分:0)

我解决了!

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