[안드로이드,Android]seekbar ,시크바

2013. 2. 7. 09:16Mobile/Android



반응형

 

MainActivity.java
package com.example.ggari_seekbar;

import android.app.Activity;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.TextView;

public class MainActivity extends Activity {
	SeekBar seekbar;
	TextView tv_val;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		seekbar=(SeekBar)findViewById(R.id.seekbar);
		tv_val=(TextView)findViewById(R.id.tv_val);
		
		seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
			public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
				tv_val.setText(" 현재 값 : " + progress);
			}

			public void onStartTrackingTouch(SeekBar seekBar) {}
			public void onStopTrackingTouch(SeekBar seekBar) {}
		});
	}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <SeekBar
        android:id="@+id/seekbar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:max="100"
        android:progress="50" />

    <TextView
        android:id="@+id/tv_val"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text=" 현재 값 : 50 " />

</LinearLayout>
반응형