Reputation: 1
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
Upvotes: 0
Views: 4887
Reputation: 5150
I didn't understand why you used two times setContentView()
with different views. this is the main mistake.
Delete one contentView from setContentView(R.layout.text_switcher_1);
setContentView(R.layout.seekbar_1);
first..here compiler confused when fetching layout view ..i think this is one of your coding mistake.
and make sure that R.id.seek
is the perfect path of the seekbar and defined in xml layout.
From this conversation.. try once like below code and delete implementation of OnSeekBarChangeListener
and its corresponding methods.
mSeekBar = (SeekBar)findViewById(R.id.seek);
mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
// TODO Auto-generated method stub
}
Upvotes: 2