久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Switch 語句只返回最后一種情況

Switch statement just returning the last case(Switch 語句只返回最后一種情況)
本文介紹了Switch 語句只返回最后一種情況的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

切換語句修復:switch 語句只返回最后一種情況,即情況 4,#0R0dfdf0FF".我該如何解決這個問題,以便文本視圖顯示在對話框中單擊的那個?我是一個新手,所以非常感謝您的幫助.

Switch statment fix: The switch statement is only returning the last case i.e case 4, "#0R0dfdf0FF". how can i fix this so the text view shows the the one clicked in the dialogue box? I'm a total newbie so yes help would really be appreciated.

public class NoteEdit extends Activity {
public EditText mTitleText;
public EditText mBodyText;
public EditText mColor;
private NotesDbAdapter mDbHelper;
private static final int DIALOG_ALERT = 10;
Long mRowId;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    mDbHelper = new NotesDbAdapter(this);
    mDbHelper.open();
    setContentView(R.layout.note_edit);
    setTitle(R.string.done);
    mTitleText = (EditText) findViewById(R.id.editTitle);
    mBodyText = (EditText) findViewById(R.id.editNote);
    mColor = (EditText) findViewById(R.id.editColor);
    mRowId = (savedInstanceState == null) ? null :
        (Long) savedInstanceState.getSerializable(NotesDbAdapter.KEY_ROWID);
    if (mRowId == null) {
        Bundle extras = getIntent().getExtras();
        mRowId = extras != null ? extras.getLong(NotesDbAdapter.KEY_ROWID)
                                : null;
    }
    populateFields();
    setupActionBar();
}
private void setupActionBar() {

    getActionBar().setDisplayHomeAsUpEnabled(true);

}
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // This ID represents the Home or Up button. In the case of this
        // activity, the Up button is shown. Use NavUtils to allow users
        // to navigate up one level in the application structure. For
        // more details, see the Navigation pattern on Android Design:
        //
        // http://developer.android.com/design/patterns/navigation.html#up-vs-back
        //
        setResult(RESULT_OK);
        finish();


    }
    return super.onOptionsItemSelected(item);
}
private void populateFields() {
    if (mRowId != null) {
        Cursor note = mDbHelper.fetchNote(mRowId);
        startManagingCursor(note);
        mTitleText.setText(note.getString(
                    note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE)));
        mBodyText.setText(note.getString(
                note.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY)));
        mColor.setText(note.getString(
                note.getColumnIndexOrThrow(NotesDbAdapter.KEY_COLOR)));
    }
}

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    saveState();
    outState.putSerializable(NotesDbAdapter.KEY_ROWID, mRowId);
}
@Override
protected void onPause() {
    super.onPause();
    saveState();
}
@Override
protected void onResume() {
    super.onResume();
    populateFields();
}
private void saveState() {
    String title = mTitleText.getText().toString();
    String body = mBodyText.getText().toString();
    String color = mColor.getText().toString();

    if (mRowId == null) {
        long id = mDbHelper.createNote(title, body, color);
        if (id > 0) {
            mRowId = id;
        }
    } else {
        mDbHelper.updateNote(mRowId, title, body, color);
    }
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main, menu);
    return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
    switch(item.getItemId()) {
    case R.id.add:
        showDialog(DIALOG_ALERT);
        return true;
    }

    return super.onMenuItemSelected(featureId, item);
}
@Override
protected Dialog onCreateDialog(int id) {
  switch (id) {
  case DIALOG_ALERT:
    // Create out AlterDialog
    android.app.AlertDialog.Builder builder = new AlertDialog.Builder(this);
    final String[] colors = {"Blue", "Green", "Yellow", "Red", "Purple"};
    builder.setTitle(R.string.body);
    builder.setItems(colors, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
        // The 'which' argument contains the index position
        // of the selected item
            switch (which){
            case 0:
                mColor.setText("#000000");
            case 1:
                mColor.setText("#0000FF");
            case 2:
                mColor.setText("#0R00FF");
            case 3:
                mColor.setText("#0R00dsdFF");
            case 4:
                mColor.setText("#0R0dfdf0FF");
            default:  
                break; 
            }
    } });
    AlertDialog dialog = builder.create();
    dialog.show();
  }
  return super.onCreateDialog(id);
}

}

推薦答案

你在 switch 分支的末尾缺少 break;.

You are missing break; at the end of the switch branches.

這篇關于Switch 語句只返回最后一種情況的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數據庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 婷婷久久五月 | 精品一区二区三区四区五区 | 色妹子综合网 | 美女天天操 | 久久久成人一区二区免费影院 | 免费观看色 | 99亚洲精品| 成人精品一区二区三区中文字幕 | 亚洲视频国产 | 国产精品国产成人国产三级 | 久久一区二区三区电影 | 久久久91精品国产一区二区精品 | 成人午夜激情 | 久久久久国产 | 正在播放国产精品 | 亚洲国产成人在线视频 | 免费久久久 | 亚洲夜夜爽 | 国产欧美一区二区三区日本久久久 | 一区二区三区日韩精品 | 中文字幕一区二区三区乱码图片 | 一区二区三区精品视频 | 狠狠爱综合 | 国产乱码精品一区二区三区中文 | 欧美一区视频 | 欧美日韩综合视频 | 成人亚洲性情网站www在线观看 | 九色91视频 | 国色天香综合网 | 紧缚调教一区二区三区视频 | 欧美午夜精品久久久久久浪潮 | 久久精品国产清自在天天线 | jⅰzz亚洲| 蜜臀网 | 色综合欧美 | 久久久高清| 在线成人 | 亚洲高清视频一区 | 成人免费视频网站在线看 | 久久成人久久 | 中文字幕亚洲精品 |