开发者

red squiggly under "id"

In the following snip, anywhere "id" appears there is a red squiggly underline (and a red-squared-X-paired-w/-a-'light bulb' icon in the left margin:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    //the id of the main layout was manually added in the XML file!
    LinearLayout ll = (LinearLayout) findViewById(R.id.main_layout);

    recButton = (Button) findViewById(R.id.recButton);
    recButton.setEnabled(true);
    recButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            startRecording();

        }
    });

    stopButton = (Button) findViewById(R.id.stopButton);
    stopButton.setEnabled(false);
    stopButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            stopRecording();
        }
    });

    playButton = (Button) findViewById(R.id.playButton);
    playButton.setEnabled(false);
    playButton.setOnClickListener(new View.OnClickListener() {
        pu开发者_如何学运维blic void onClick(View view) {
            playRecording();
        }
    });

    analyzerButton = (Button) findViewById(R.id.analyzerButton);
    analyzerButton.setEnabled(false);
    analyzerButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            analyzeRecording();
        }
    });

    audioShape = new AudioShape(this);
    ll.addView(audioShape);
}

Mouseover is "id cannot be resolved or is not a field."

I only copied over some Open Data Kit (ODK) .java files into a new Android starter, Hello-type app. Have done nothing else, certainly haven't created any UI for it (do I need to?). The files I have plugged into Eclipse are this: http://code.google.com/p/opendatakit/source/browse/src/net/hugo/audioAnalyzer/?repo=listen&r=1146e38a2c144b6b338f694bc39fda3c26c3d1e1

Don't know how to proceed. Thanks for any help.


You do need to create new UI for it. When you add custom IDs e.g. android:id="@+id/myButton" to elements in a layout file (XML file under res/layout) the Android build system will make an ID constant R.id.myButton in your project's custom-build R class. So find the main layout from your example project and copy it over.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜