Monday, February 24, 2014

Newbie help, neon question


MainActivity:



package com.example.led;

import java.util.Timer;
import java.util.TimerTask;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;

public class MainActivity extends Activity {
private int currentColor = 0;
final int [] colors = new int [] {
R.color.color1,
R.color.color2,
R.color.color3,
R.color.color4,
R.color.color5,
R.color.color6

};
final int [] names = new int [] {
R.id.view01,
R.id.view02,
R.id.view03,
R.id.view04,
R.id.view05,
R.id.view06,
};
TextView [] views = new TextView [names.length];

Handler handler = new Handler () {
@ Override
public void handleMessage (Message msg) {
if (msg.what == 0x123) {
for (int i = 0; i views [i]. setBackgroundResource (colors [
(I + currentColor)% names.length]);
}
currentColor + +;
}
super.handleMessage (msg);
}
};
@ Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
for (int i = 0; i views [i] = (TextView) findViewById (names [i]);
}
new Timer (). schedule (new TimerTask () {
@ Override
public void run () {
handler.sendEmptyMessage (0x123);
}
}, 0,200);
}
}


color.xml




# 00ff00
# ff0000
# 0000ff
# 00ff00
# ffff00
# 00ffff



activity_main:

android: layout_width = "fill_parent"
android: layout_height = "fill_parent"
>
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
android: layout_gravity = "center"
android: width = "320px"
android: height = "320px"
android: background = "# f00"
/>
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
android: layout_gravity = "center"
android: width = "280px"
android: height = "280px"
android: background = "# 0f0"
/>
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
android: layout_gravity = "center"
android: width = "240px"
android: height = "240px"
android: background = "# 00f"
/>
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
android: layout_gravity = "center"
android: width = "200px"
android: height = "200px"
android: background = "# ff0"
/>
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
android: layout_gravity = "center"
android: width = "160px"
android: height = "160px"
android: background = "# f0f"
/>
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
android: layout_gravity = "center"
android: width = "120px"
android: height = "120px"
android: background = "# 0ff"
/>


Questions are as follows:
1 In MainActivity, two final methods. When you define a color array, the array why color display error:. Color * can not be resolved or is not afeild
2 Similarly in the second definition array names, why view * a problem occurs and the same mistakes?
Find Great God help me doubts!<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
import com.example.led.R;
Reply:
cited a floor hjywyj reply:
import com.example.led.R;

Ah, still wrong after import package!

No comments:

Post a Comment