单击按钮上的事件

时间:2016-03-05 10:49:26

标签: android

我试图在一个按钮点击功能上放置不同的事件。每个操作都使用不同的模式从API中提取数据:手动添加数据,编辑数据或添加数据。 一个单击按钮用于执行这些操作

按钮正在为两个事件工作,但它不适用于最后一个事件...... 请帮忙......

    public void onClickaddMovie(View v) {

    int operation = getIntent().getIntExtra("operationMode", MovieDBconstanse.ADD_MODE);
    if (operation == MovieDBconstanse.ADD_MODE) {
        Movie thisMovie = new Movie();
        thisMovie.setTitle(movieName.getText().toString());
        thisMovie.setDescription(movieSummery.getText().toString());
        thisMovie.setURL(movieURL.getText().toString());

        mydb.insertValueToDb(thisMovie);
        setResult(RESULT_OK);
        finish();
        //Intent okIntent = new Intent(this, MainActivity.class);
        //startActivityForResult(okIntent, MovieDBconstanse.MAIN_SCREEN);
    } else if (operation == MovieDBconstanse.EDIT_MODE) {

        //Movie thisMovie = new Movie();
        selectedMovie.setTitle(movieName.getText().toString());
        selectedMovie.setDescription(movieSummery.getText().toString());
        selectedMovie.setURL(movieURL.getText().toString());

        mydb.editMovie(selectedMovie);
        setResult(RESULT_OK);
        finish();
        //WORNG!
        // Intent editIntent = new Intent(this, Edit_MovieScreen.class);
        // startActivityForResult(editIntent,MovieDBconstanse.EDIT_SCREEN);
    }

//        else if (operation==MovieDBconstanse.ITERNET_ADD_MODE){
//
//            mydb = new MovieHandler(this);
//
//            Movie thisMovie = new Movie();
//            thisMovie.setTitle(movieName.getText().toString());
//            thisMovie.setDescription(movieSummery.getText().toString());
//            thisMovie.setURL(movieURL.getText().toString());
//            Toast.makeText(Edit_MovieScreen.this,"data upload to  db",Toast.LENGTH_LONG).show();
//
//            mydb.insertValueToDb(thisMovie);
//            setResult(RESULT_OK);
//            finish();
//
//        }

0 个答案:

没有答案