Мне нужна ваша помощь. в моем диалоговом окне есть 2 радиообмена. Я хочу отключить или включить некоторые виды в этом диалоговом окне, в зависимости от того, какой радиатор проверен пользователем.Как включить отключить диалоговые окна динамически
мой макет для диалога: inc_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/inc_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="16dp"
android:hint="Название дохода"
/>
<EditText
android:id="@+id/inc_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="4dp"
android:hint="Сумма дохода"
/>
<TextView
android:id="@+id/tvChkBoxIncType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="4dp"
android:layout_marginTop="4dp"
android:text="Тип дохода:" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RadioGroup
android:id="@+id/RadioGroup1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/inc_random"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:onClick="onRadioButtonClicked"
android:text="Разовый" />
<RadioButton
android:id="@+id/inc_const"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="9dp"
android:checked="true"
android:onClick="onRadioButtonClicked"
android:text="Постоянный" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/DataPick1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginLeft="16dp"
android:text="Начало периода:"
android:enabled="false"/>
<EditText
android:id="@+id/inc_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DD"
android:enabled="false" >
</EditText>
<EditText
android:id="@+id/inc_month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MM"
android:enabled="false">
</EditText>
<EditText
android:id="@+id/inc_year"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="false"
android:text="YYYY" >
</EditText>
</LinearLayout>
<EditText
android:id="@+id/inc_period"
android:layout_width="wrap_content"
android:enabled="false"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:text="Каждые Х дней" >
</EditText>
</LinearLayout>
Строительство этого диалога:
protected Dialog onCreateDialog(int id) {
AlertDialog.Builder adb = new AlertDialog.Builder(this);
adb.setTitle("Добавить доход");
view = (LinearLayout) getLayoutInflater()
.inflate(R.layout.inc_dialog, null);
// устанавливаем ее, как содержимое тела диалога
adb.setView(view) .setPositiveButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
}) .setNegativeButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Toast.makeText(getApplicationContext(),"Добавлено", Toast.LENGTH_SHORT).show();
}
}); ;
return adb.create();
}
функции OnClick, что я называю в АКТИВНОСТИ
public void onRadioButtonClicked(){
switch(view.getId()) {
case R.id.inc_const:
findViewById(R.id.DataPick1).setEnabled(true);
break;
case R.id.inc_random:
findViewById(R.id.DataPick1).setEnabled(false);
break;
}
};
Если это необходимо в целом Код операции. Income.java
package com.example.pocketbooker;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class Income extends Activity{
LinearLayout view;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle("Доходы");
setContentView(R.layout.income_const);
}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.inoutgo, menu);
return super.onCreateOptionsMenu(menu);
}
protected Dialog onCreateDialog(int id) {
AlertDialog.Builder adb = new AlertDialog.Builder(this);
adb.setTitle("Добавить доход");
view = (LinearLayout) getLayoutInflater()
.inflate(R.layout.inc_dialog, null);
// устанавливаем ее, как содержимое тела диалога
adb.setView(view) .setPositiveButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
}) .setNegativeButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Toast.makeText(getApplicationContext(),"Добавлено", Toast.LENGTH_SHORT).show();
}
}); ;
return adb.create();
}
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.plus:
showDialog(1);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public void onRadioButtonClicked(){
switch(view.getId()) {
case R.id.inc_const:
findViewById(R.id.DataPick1).setEnabled(true);
break;
case R.id.inc_random:
findViewById(R.id.DataPick1).setEnabled(false);
break;
}
};
}
Так что я хочу, чтобы изменить свойство зрения в моем диалоге динамически. Как я могу это сделать? Как я могу вызвать диалоговые представления из моей функции Activity? И извините за мой английский, я из Казахстана. Пожалуйста, помогите.
Кнопка Initialze Radio затем проверяет, не проверено или не включено/выключено согласно – Raghunandan