Android : Seek bar and button don't work

on Saturday, September 6, 2014


I want to write a simple android application with one button and one slider : my java program is as following :



package com.example.android.apis.view;

import com.example.android.apis.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher;

/**
* Uses a TextSwitcher.
*/
public class TextSwitcher1 extends Activity implements ViewSwitcher.ViewFactory,
View.OnClickListener, OnSeekBarChangeListener {

SeekBar mSeekBar;
TextView mProgressText;
TextView mTrackingText;
private TextSwitcher mSwitcher;

private int mCounter = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.text_switcher_1);
setContentView(R.layout.seekbar_1);

mSeekBar = (SeekBar)findViewById(R.id.seek);
mSeekBar.setOnSeekBarChangeListener(this);

mProgressText = (TextView)findViewById(R.id.progress);
mTrackingText = (TextView)findViewById(R.id.tracking);

mSwitcher = (TextSwitcher) findViewById(R.id.switcher);
mSwitcher.setFactory(this);

Button nextButton = (Button) findViewById(R.id.next);
nextButton.setOnClickListener(this);

updateCounter();
}

public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
mProgressText.setText(progress + " " +
getString(R.string.seekbar_from_touch) + "=" + fromTouch);
}

public void onStartTrackingTouch(SeekBar seekBar) {
mTrackingText.setText(getString(R.string.seekbar_tracking_on));
}

public void onStopTrackingTouch(SeekBar seekBar) {
mTrackingText.setText(getString(R.string.seekbar_tracking_off));
}

public void onClick(View v) {
mCounter++;
updateCounter();
}

private void updateCounter() {
mSwitcher.setText(String.valueOf(mCounter));
}

public View makeView() {
TextView t = new TextView(this);
t.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
t.setTextSize(36);
return t;
}
}


I got this error : The method setOnSeekBarChangeListener(SeekBar.OnSeekBarChangeListener) in the type SeekBar is not applicable for the arguments (TextSwitcher1) in this line : mSeekbar.setonSeekbarChangeListener(this);


I don't know what is this problem,would you please help me to solve it. Thank you very much in advance, Stefan


0 comments:

Post a Comment