我在代码中实现微调器时遇到问题。不太确定它是如何工作的。但这里是我想要做的一个简短的想法。(例如:单击微调器,您有 2 个选项“第 2 页”和“第 3 页”。因此,如果您单击“第 2 页”,它将转到包含新内容的第二页。有没有办法做到这一点?
我也有图像按钮可以转到下一页和返回。只想实现一个微调框,以便您可以更快地导航到不同的页面。
public class AppActivity extends Activity implements OnTouchListener {
private MediaPlayer mp;
ImageButton button;
ImageButton button3;
ImageView imgView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final String[] spstr = getResources().getStringArray(R.array.spinnervalue);
final Spinner sp = (Spinner)findViewById(R.id.spinner1);
final ArrayAdapter<String> ar = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,spstr);
sp.setAdapter(ar);
sp.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
String s=((TextView)view).getText().toString();
if(s.equals("page2"))
startActivity(new Intent(view.getContext(),App2Activity.class));
if(s.equals("page3"))
startActivity(new Intent(view.getContext(),App3Activity.class));
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
public void addListenerOnButton() {
final Context context = this;
button3 = (ImageButton) this.findViewById(R.id.imageButton5);
button3.setOnTouchListener(this);
mp = MediaPlayer.create(this, R.raw.vanilla_twilight);
button = (ImageButton) findViewById(R.id.imageButton1);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(context, App2Activity.class);
startActivity(intent);
}
});
}
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
MediaPlayer mp = MediaPlayer.create(getBaseContext(),
R.raw.vanilla_twilight);
mp.start();
mp.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.release();
}
});
};
return true;
}
}
XML
<Spinner
android:id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
Logcat 错误
05-22 01:32:40.058: E/SpannableStringBuilder(16206): SPAN_EXCLUSIVE_EXCLUSIVE 跨度不能有零长度 05-22 01:32:40.058: E/SpannableStringBuilder(16206): SPAN_EXCLUSIVE_EXCLUSIVE 跨度不能有零长度
资源 page2 page3