• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps android:id problem

pauleee

Lurker
hello, i am new to android development and eclipse ,, please assist with this simple issue cause its got me...

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/main_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/red" />

<SeekBar
android:id="@+id/red_seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="255" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/blue" />

<SeekBar
android:id="@+id/blue_seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="255" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/green"
android:max="255" />

<SeekBar
android:id="@+id/green_seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="255" />

</LinearLayout>





package com.example.colors;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;

public class MainActivity extends Activity implements OnSeekBarChangeListener
{
private LinearLayout frame;
private SeekBar redSeekBar, blueSeekBar, greenSeekBar;

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

frame = (LinearLayout) findViewById(R.id.main_frame);

redSeekBar = (SeekBar) findViewById(R.id.red_seekbar);
blueSeekBar = (SeekBar) findViewById(R.id.blue_seekbar);
greenSeekBar = (SeekBar) findViewById(R.id.green_seekbar);

redSeekBar.setOnSeekBarChangeListener(this);
blueSeekBar.setOnSeekBarChangeListener(this);
greenSeekBar.setOnSeekBarChangeListener(this);
}

@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser)
{
frame.setBackgroundColor(getColorFromSeekbars());
}

@Override
public void onStartTrackingTouch(SeekBar seekBar)
{
// do nothing
}

@Override
public void onStopTrackingTouch(SeekBar seekBar)
{
// do nothing
}

private int getColorFromSeekbars()
{
return Color.argb(255, redSeekBar.getProgress(),
greenSeekBar.getProgress(), blueSeekBar.getProgress());
}
}


The error is the following R.id values "cannot be resolved or is not a field."

frame = (LinearLayout) findViewById(R.id.main_frame);

redSeekBar = (SeekBar) findViewById(R.id.red_seekbar);
blueSeekBar = (SeekBar) findViewById(R.id.blue_seekbar);
greenSeekBar = (SeekBar) findViewById(R.id.green_seekbar);

Assistance is greatly appreciated..

Thanks Paul
 
Paul

In the eclipse menu , click on the project menu and click clean project. I have had this type of thing where eclipse is not auto building or cleaning the project so the code does not see the XML layout references

Thanks

TimCS
 
Back
Top Bottom