ورود

View Full Version : مشکل RadioButton



Pam.goudarzi
چهارشنبه 01 مرداد 1393, 11:02 صبح
سلام. من جدیدا دارم با RadioButton کار میکنم. میخواستم کاری کنم که فقط بشه یک رادیو باتن رو انتخاب کرد و اگه کاربر روی رادیوباتن بعدی کلیک کرد، رادیو باتن بعدی از حالت چک شده در بیاد. اما نمی دونم چجوری!!!
و یکی هم که میخوام عکس ImageView رو عوض کنم اما با هر دستوری که امتحان کردم نشد(Setimagedrawable و ...) کمکی می کنید؟
setContentView(R.layout.activity_main); final MediaPlayer mm = MediaPlayer.create(MainActivity.this, R.raw.pitch14);
RadioButton forteen = (RadioButton) findViewById(R.id.radioButton1);
RadioButton sixteen = (RadioButton) findViewById(R.id.radioButton2);
RadioButton twenty = (RadioButton) findViewById(R.id.radioButton3);
final ImageView anti = (ImageView) findViewById(R.id.imageView1);
if(forteen.isChecked()== true)
{
anti.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
mm.start();

}
});

parvizwpf
چهارشنبه 01 مرداد 1393, 11:24 صبح
http://www.mkyong.com/android/android-radio-buttons-example/
http://stackoverflow.com/questions/5223656/how-can-i-change-the-image-of-an-imageview-on-android

miladu
چهارشنبه 01 مرداد 1393, 11:51 صبح
شما باید RadioButton هاتو داخل تگ RadioGroup بزاری

برای ImageView هم میتونی از setBackgroundResource استفاده کنی




anti.setBackgroundResource(R.drawable.img);

Pam.goudarzi
پنج شنبه 02 مرداد 1393, 12:58 عصر
ممنون. حالا می تونم از دستور if استفاده کنم دیگه؟