开发者

R.layout.chronometer cannot be resolved or is not a field- android error

开发者 https://www.devze.com 2023-02-05 02:06 出处:网络
I tried simple stopwatch program from http://developer.android.com/resources/samples/ApiDemos/src/com/example/andr开发者_JS百科oid/apis/view/ChronometerDemo.html.

I tried simple stopwatch program from http://developer.android.com/resources/samples/ApiDemos/src/com/example/andr开发者_JS百科oid/apis/view/ChronometerDemo.html.

The following error is coming

"R.layout.chronometer cannot be resolved or is not a field"

I don't know how to fix it.

Thank you.


public class video extends Activity implements android.view.View.OnClickListener{
    /** Called when the activity is first created. */
    public Chronometer cm;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
         cm=(Chronometer)findViewById(R.id.Chronometer01);
        Button btn1=(Button)findViewById(R.id.Button01);
        btn1.setText("START");
        btn1.setOnClickListener(this);
        Button btn2=(Button)findViewById(R.id.Button02);
        btn2.setText("STOP");
        btn2.setOnClickListener(this);
        Button btn3=(Button)findViewById(R.id.Button03);
        btn3.setText("RESET");
        btn3.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        // TODO Auto-generated method stub
        int id=view.getId();
        switch (id) {
        case R.id.Button01:
            cm.start();
            break;
        case R.id.Button02:
            cm.stop();
            break;
        case R.id.Button03:
             cm.setBase(SystemClock.elapsedRealtime());
            break;

    }



}}


for this to work you must have a chronometer.xml file in your res/layout.

here you have the source code for this file in the example

0

精彩评论

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