报警教程:alarmDetails无法解析为变量

时间:2014-01-12 04:39:12

标签: android alarm

我知道这是一个愚蠢的问题,但我在Android开发方面真的很新。我已经按照关于在这个网站Create an Alarm Clock in Android上做一个简单警报的教程,但我认为autor忘了编写一些变量行,因为我在每一行中都有alarmDetails cannot resolve as a variable这样的几行中出现错误{{1 }}。我不知道该行的变量类型是什么,这里是完整的代码:

更新问题已解决,但我收到了另一个错误:alarmDetails。我认为这是同样的问题,一些代码没有放在教程上。这是我的班级alarmTone cannot resolve as a field

的代码
AlarmDetailsActivity

和类AlarmModel

的代码
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.LinearLayout;
import android.view.View.OnClickListener;
import android.view.View;
import android.content.Intent;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.widget.*;
import android.net.Uri;
import dev.serabutan.socioalarm.AlrmModel;

public class AlarmDetailsActivity extends Activity {


    AlrmModel alarmDetails; 


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.alarm_details);
        getActionBar().setTitle("Create New Alarm");
        getActionBar().setDisplayHomeAsUpEnabled(true);

    final LinearLayout ringToneContainer = (LinearLayout) findViewById(R.id.alarm_ringtone_container);
    ringToneContainer.setOnClickListener(new OnClickListener(){
        @Override
        public void onClick(View v){
            Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
            startActivityForResult(intent, 1);
        }
    });
    }
Uri alarmTone;

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data){
        super.onActivityResult(requestCode, resultCode, data);
        if(resultCode == RESULT_OK){
            switch (requestCode){
                case 1:{

                    alarmDetails.alarmTone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
                    //it's says error : alarmTone Cannot resolve as a field
                    TextView txtToneSelection = (TextView) findViewById(R.id.alarm_label_tone_selection);
                    txtToneSelection.setText(RingtoneManager.getRingtone(this, alarmDetails.alarmTone).getTitle(this));
                    break;
                }
                default:{
                    break;
                }
            }
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu){
        getMenuInflater().inflate(R.menu.alarm_details, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item){
        switch(item.getItemId()){
            case android.R.id.home:{
                finish();
                break;
            }

            case R.id.action_save_alarm_details:{
                updateModelFromLayout();
                finish();
            }
        }
        return super.onOptionsItemSelected(item);
    }


    private void updateModelFromLayout() {

    TimePicker timePicker = (TimePicker) findViewById(R.id.alarm_details_time_picker);
    alarmDetails.timeMinute = timePicker.getCurrentMinute().intValue();
    alarmDetails.timeHour = timePicker.getCurrentHour().intValue();

    EditText edtName = (EditText) findViewById(R.id.alarm_details_name);
    alarmDetails.name = edtName.getText().toString();

    CheckBox chkWeekly = (CheckBox) findViewById(R.id.alarm_details_repeat_weekly);
    alarmDetails.repeatWeekly = chkWeekly.isChecked();

    CheckBox chkSunday = (CheckBox) findViewById(R.id.alarm_details_repeat_sunday);
    alarmDetails.setRepeatingDay(AlrmModel.SUNDAY, chkSunday.isChecked());

    CheckBox chkMonday = (CheckBox) findViewById(R.id.alarm_details_repeat_monday);
    alarmDetails.setRepeatingDay(AlrmModel.MONDAY, chkMonday.isChecked());

    CheckBox chkTuesday = (CheckBox) findViewById(R.id.alarm_details_repeat_tuesday);
    alarmDetails.setRepeatingDay(AlrmModel.TUESDAY, chkTuesday.isChecked());

    CheckBox chkWednesday = (CheckBox) findViewById(R.id.alarm_details_repeat_wednesday);
    alarmDetails.setRepeatingDay(AlrmModel.WEDNESDAY, chkWednesday.isChecked());

    CheckBox chkThursday = (CheckBox) findViewById(R.id.alarm_details_repeat_thursday);
    alarmDetails.setRepeatingDay(AlrmModel.THURSDAY, chkThursday.isChecked());

    CheckBox chkFriday = (CheckBox) findViewById(R.id.alarm_details_repeat_friday);
    alarmDetails.setRepeatingDay(AlrmModel.FRIDAY, chkFriday.isChecked());

    CheckBox chkSaturday = (CheckBox) findViewById(R.id.alarm_details_repeat_saturday);
    alarmDetails.setRepeatingDay(AlrmModel.SATURDAY, chkSaturday.isChecked());

    alarmDetails.isEnabled = true;
}


}

我该怎么办?

1 个答案:

答案 0 :(得分:0)

尝试使用AlarmModel:在教程中,AlarmModel中的变量似乎与alarmDetails的变量匹配