获取所有RadioGroup选项ID

时间:2015-11-18 13:55:24

标签: java android

  

为什么可以更改背景颜色但不设置   新文本????

RadioGroup allRadioGroups[] = {button1, button2};
  

为什么我可以做这些:

allRadioGroups[0].getChildAt(1).setBackgroundColor(Color.parseColor("#216059"));

allRadioGroups[1].getChildAt(3).setEnables(false);
  

但是我做不到这些:

allRadioGroups[0].getChildAt(1).isChecked();

allRadioGroups[1].getChildAt(3).setText("My Text");

1 个答案:

答案 0 :(得分:0)

  

但是我做不到这些:

using System;
using System.Threading.Tasks;
using EasyNetQ;
using EasyNetQ.Consumer;
using EasyNetQ.Loggers;
using EasyNetQ.Topology;

namespace ConsoleApplication4
{
    public static class RabbitAdvancedBusConsumeExtension
    {
       public static IDisposable Consume(this IAdvancedBus bus, IQueue queue, Action<byte[], MessageProperties, MessageReceivedInfo> onMessage)
    {
        return bus.Consume(queue, (bytes, properties, info) => ExecuteSynchronously(() => onMessage(bytes, properties, info)));
    }

    public static IDisposable Consume(this IAdvancedBus bus, IQueue queue, Action<byte[], MessageProperties, MessageReceivedInfo> onMessage, Action<IConsumerConfiguration> configure)
    {
        return bus.Consume(queue, (bytes, properties, info) => ExecuteSynchronously(() => onMessage(bytes, properties, info)), configure);
    }

    private static Task ExecuteSynchronously(Action action)
    {
        var tcs = new TaskCompletionSource<object>();
        try
        {
            action();
            tcs.SetResult(null);
        }
        catch (Exception e)
        {
            tcs.SetException(e);
        }
        return tcs.Task;
    }
}

class Program
{
    static void Main(string[] args)
    {
        var bus = RabbitHutch.CreateBus("host=localhost", x => x.Register<IEasyNetQLogger>(s => new ConsoleLogger()));

        var queue = bus.Advanced.QueueDeclare();
        bus.Advanced.Consume(queue, (bytes, properties, info) =>
        {
            // .....
        });
    }
}
}

因为allRadioGroups[0].getChildAt(1).isChecked(); allRadioGroups[1].getChildAt(3).setText("My Text"); 方法返回getChildAt对象。ViewisChecked方法不是来自setText类。这些方法来自类(RadioButton)它扩展了View类

因此,为了让这些行工作,请将View返回View

RadioButton