Newbie help, neon problem

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<names.length;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<names.length;i++){
views[i]=(TextView) findViewById(names[i]);
}
new Timer().schedule(new TimerTask(){
@Override
public void run(){
handler.sendEmptyMessage(0x123);
}
},0,200);
}
}


color.xml


<?xml version="1.0" encoding="UTF-8"?>
<resources>
<color name="color1">#00ff00</color>
<color name="color2">#ff0000</color>
<color name="color3">#0000ff</color>
<color name="color4">#00ff00</color>
<color name="color5">#ffff00</color>
<color name="color6">#00ffff</color>
</resources>


activity_main:
<?xml version="1.0" encoding="UTF-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView android:id="@+id/view01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:width="320px"
android:height="320px"
android:background="#f00"
/>
<TextView android:id="@+id/view02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:width="280px"
android:height="280px"
android:background="#0f0"
/>
<TextView android:id="@+id/view03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:width="240px"
android:height="240px"
android:background="#00f"
/>
<TextView android:id="@+id/view04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:width="200px"
android:height="200px"
android:background="#ff0"
/>
<TextView android:id="@+id/view05"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:width="160px"
android:height="160px"
android:background="#f0f"
/>
<TextView android:id="@+id/view06"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:width="120px"
android:height="120px"
android:background="#0ff"
/>
</FrameLayout>

The problems are as follows:
In MainActivity 1, two final methods. The definition of color arrays, why color array display error: color* can not be resolved or is not afeild.
2 as defined in the second array names, why view* appears and the last of the same mistake?
Ask God to help me out!

Started by Lucy at November 26, 2016 - 11:04 PM

import com.example.led.R;

Posted by Joy at December 10, 2016 - 11:46 PM

Not ah, the package is imported or wrong!

Posted by Lucy at December 11, 2016 - 11:47 PM