如何使用prev按钮和下一个按钮更改搜索栏

时间:2015-08-21 22:16:50

标签: android xml android-animation seekbar android-seekbar

在我的TopRated.java文件中,我有一个图像视图,在使用搜索栏时会发生变化。当使用下一个和上一个按钮时,它也会发生变化。但是,我希望按钮和导引头同步,也就是说,当按下下一个按钮时,我希望它也将导引头向上移动一个,当按下前一个按钮时,我希望它也移动寻求者一个人。 请帮忙

这是我的TopRated.java文件

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.SeekBar;


public class TopRated extends Activity {
SeekBar imgseekbar;
ImageView iconimageview;
Button prevbutton;
Button nextbutton;
int progress=0;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.toprated);
    iconimageview=(ImageView)findViewById(R.id.imageView);
    imgseekbar=(SeekBar)findViewById(R.id.seekBar);
    prevbutton=(Button)findViewById(R.id.button8);
    nextbutton=(Button)findViewById(R.id.button9);
    iconimageview.setImageResource(R.drawable.diablo);

    imgseekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            updateImageResource(progress);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });
    prevbutton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            progress--;
            updateImageResource(progress);
        }
    });
    nextbutton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            progress++;
            updateImageResource(progress);
        }
    });
}

private void updateImageResource(int progress) {
    if (progress==2) {
        iconimageview.setImageResource(R.drawable.eye);
    }else if (progress==3) {
        iconimageview.setImageResource(R.drawable.facebook);
    }else if (progress==4) {
        iconimageview.setImageResource(R.drawable.google);
    }else if (progress==5) {
        iconimageview.setImageResource(R.drawable.house);
    }else if (progress==6) {
        iconimageview.setImageResource(R.drawable.mail);
    }else if (progress==7) {
        iconimageview.setImageResource(R.drawable.pen);
    }else if (progress==8) {
        iconimageview.setImageResource(R.drawable.photos);
    }else if (progress==9) {
        iconimageview.setImageResource(R.drawable.skype);
    }else if (progress==10)
    iconimageview.setImageResource(R.drawable.twitter);

}
}

这是我的toprated.xml文件

<?xml version="1.0" encoding="utf-8"?>

<SeekBar
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/seekBar"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:max="10"/>

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView"
    android:layout_below="@+id/seekBar"
    android:layout_centerHorizontal="true"
    android:minHeight="50dp"
    android:minWidth="50dp"
    android:background="@drawable/icon_animation"/>

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Prev"
    android:id="@+id/button8"
    android:layout_alignBottom="@+id/imageView"
    android:layout_toStartOf="@+id/imageView"
    android:layout_marginRight="5dp" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Next"
    android:id="@+id/button9"
    android:layout_alignBottom="@+id/imageView"
    android:layout_toEndOf="@+id/button8"
    android:layout_marginLeft="50dp" />

我还有另一个xml,它包含我的所有图像,icon_animation.xml

请帮忙! 任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

使用以下行更新搜索栏

seekbar.setProgress(int)