۱۳۹۴/۱۱/۱۷, ۰۲:۱۵ ب.ظ
۱۳۹۴/۱۱/۱۷, ۰۵:۴۴ ب.ظ
سلام
Radiobutton ها درون container مخصوص خودشون که RadioGroup هستش قرار دارن
برای دسترسی مستقیم به RadioButton باید ابتدا به RadioGroup دسترسی پیدا کنید
سپس میتونید به Child های درون اون که همون Radiobutton ها هستن دسترسی داشته باشید
Radiobutton ها درون container مخصوص خودشون که RadioGroup هستش قرار دارن
برای دسترسی مستقیم به RadioButton باید ابتدا به RadioGroup دسترسی پیدا کنید
سپس میتونید به Child های درون اون که همون Radiobutton ها هستن دسترسی داشته باشید
۱۳۹۴/۱۱/۱۸, ۰۷:۳۳ ب.ظ
مرسی دوست عزیز مشکل منم در دسترسی هست دیگه چطوری به خود ردیو باتن و بعدش به child اون دسترسی پیدا کنیم؟
مشکل منم همینه
میشه به یه کد ساده نشون بدید؟
ممنون
مشکل منم همینه
میشه به یه کد ساده نشون بدید؟
ممنون
۱۳۹۴/۱۱/۱۸, ۱۱:۱۹ ب.ظ
این هم یک مثال در رابطه از استفاده از RadioButton و RadioGroup
اگه باز هم نیاز به دسترسی و کنترل بیشتری بر روی RadioGroup یا Radiobutton داشتید اعلام کنید چه نوع دسترسی نیاز دارید یا دقبقا میخواید چیکار کنید.
اگه باز هم نیاز به دسترسی و کنترل بیشتری بر روی RadioGroup یا Radiobutton داشتید اعلام کنید چه نوع دسترسی نیاز دارید یا دقبقا میخواید چیکار کنید.
کد:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.mahdi.myapplication.MainActivityFragment"
tools:showIn="@layout/activity_main">
<RadioGroup
android:layout_marginTop="25dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#CCBBEE"
android:id="@+id/rg">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton 1"
android:id="@+id/rb1"
android:checked="false"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton 2"
android:id="@+id/rb2"
android:checked="false"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton 3"
android:checked="false"
android:id="@+id/rb3"/>
</RadioGroup>
</RelativeLayout>
کد:
RadioGroup rg = (RadioGroup) findViewById(R.id.rg);
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.rb1 :
Toast.makeText(MainActivity.this,"RadioButton 1 is Checked", Toast.LENGTH_SHORT).show();
break;
case R.id.rb2 :
Toast.makeText(MainActivity.this,"RadioButton 2 is Checked", Toast.LENGTH_SHORT).show();
break;
case R.id.rb3 :
Toast.makeText(MainActivity.this,"RadioButton 3 is Checked", Toast.LENGTH_SHORT).show();
break;
}
}
});
RadioButton rb1 = (RadioButton) findViewById(R.id.rb2);
rb1.setChecked(true);