我想在我的Android应用中添加和滑块,但是我收到了这个错误:
错误:找不到符号方法 addOnPageChangeListener(MainActivity)
这些是我的依赖项:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.daimajia.slider:library:1.0.9@aar'
compile 'com.squareup.picasso:picasso:2.3.2'
}
这是我的代码:
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import com.daimajia.slider.library.Indicators.PagerIndicator;
import com.daimajia.slider.library.SliderLayout;
import com.daimajia.slider.library.Tricks.ViewPagerEx;
import java.util.HashMap;
public class MainActivity extends AppCompatActivity implements ViewPagerEx.OnPageChangeListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
HashMap<String, Integer> file_maps = new HashMap<>();
file_maps.put("Image1", R.drawable.image_1);
file_maps.put("Image2", R.drawable.image_2);
file_maps.put("Image3", R.drawable.image_3);
SliderLayout imageSlider = (SliderLayout) findViewById(R.id.slider);
for (String name : file_maps.keySet()) {
SliderTextView SliderTextView = new SliderTextView(this);
SliderTextView.description(name).image(file_maps.get(name));
imageSlider.addSlider(SliderTextView);
}
imageSlider.setCustomIndicator((PagerIndicator) findViewById(R.id.custom_indicator));
imageSlider.setPresetTransformer(SliderLayout.Transformer.Tablet);
// THIS IS THE PROBLEM
imageSlider.addOnPageChangeListener(this);
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}
@Override
public void onPageSelected(int position) {}
@Override
public void onPageScrollStateChanged(int state) {}
}
有人知道,可能出现什么问题以及如何解决问题?
答案 0 :(得分:1)
您正在使用AndroidImageSlider库的1.0.9。
compile 'com.daimajia.slider:library:1.0.9@aar'
此版本没有这种方法,因为您可以查看here:
您应该使用最新版本:
compile 'com.daimajia.slider:library:1.1.5@aar'