How do I pass the value of an array to another class?

时间:2015-05-12 23:05:23

标签: java android arrays android-studio

I'm trying to pass in an array value of colors that is in another class to FunFactsActivity in Android Studio. Right now, I'm getting an error
td{ position:relative; } td:nth-child(2n-1)::after{ background:red; bottom:-5px; content:""; display:block; position:absolute; right:-2px; top:-5px; width:2px; } setBackgroundColor(int) in View cannot be applied to (java.lang.String).

From what I understand, I can't pass in an int into it since its a String, but I'm just trying to make the colors i already have in that array fade every few seconds/intervals to the relativeLayout background in a thread and can't get it right. What am I doing wrong?

FunFactsActivity.java

relativeLayout.setBackgroundColor(mColorWheel.mColors[currentColor]);

ColorWheel.java

// update background color of relativeLayout every few seconds.
private void updateColor()
{
    final RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.relativeLayout);
    int color = mColorWheel.getColor();
    runOnUiThread(new Runnable()
    {

        @Override
        public void run()
        {

            if (currentColor > mColorWheel.mColors.length - 1)
            {
                currentColor = 0;

            }
            relativeLayout.setBackgroundColor(mColorWheel.mColors[currentColor]);

            currentColor++;

        }// end of run
    });

}

2 个答案:

答案 0 :(得分:2)

Your http://myhost/mypath?value=somevalue class is already calling ColorWheel in Color.parseColor function. Just use the function as it is getting a random color already.

getColor

or if you want to use the mColors array:

relativeLayout.setBackgroundColor(mColorWheel.getColor());

答案 1 :(得分:1)

Didn't go through the whole code, but when setting the color in Android, you either:

  • provide an @using (Html.BeginForm("LeggTilUtdannelse", "Utdannelse", FormMethod.Post, new { @class = "form-horizontal" })) { @Html.AntiForgeryToken() <div class="form-group"> @Html.LabelFor(m => m.Studiested, new { @class = "col-md-2 control-label" }) <div class="col-md-10"> @Html.TextBoxFor(m => m.Studiested, new { @class = "form-control", autocomplete = "off" }) </div> @Html.ValidationMessageFor(m => m.Studiested) </div> <div class="form-group"> @Html.LabelFor(m => m.Beskrivelse, new { @class = "col-md-2 control-label" }) <div class="col-md-10"> @Html.TextBoxFor(m => m.Beskrivelse, new { @class = "form-control", autocomplete = "off" }) </div> </div> <div class="form-group"> @Html.LabelFor(m => m.Fra, new { @class = "col-md-2 control-label" }) <div class="col-md-10"> @Html.TextBoxFor(m => m.Fra, new { @class = "form-control", autocomplete = "off" }) </div> </div> <div class="form-group"> @Html.LabelFor(m => m.Til, new { @class = "col-md-2 control-label" }) <div class="col-md-10"> @Html.TextBoxFor(m => m.Til, new { @class = "form-control", autocomplete = "off" }) </div> </div> <div class="form-group"> <div class="col-md-offset-2 col-md-10"> <input type="submit" class="btn btn-default" value="Legg til" /> </div> </div> which is a reference to the color id, for example: int
  • provide a R.color.my_red object. In your case if you want to convert hex value to a Color, call Color