什么可能是我的代码可能出错

时间:2014-06-17 16:53:33

标签: android

那里......代码可能出现的错误 -

if (v ==  resetButton){ 
    memoryRecord.getText().clear(); 

因为它不起作用

public class MainCodeActivity extends ActionBarActivity implements OnClickListener  {

    private EditText memoryRecord;

    private Button saveButton;
    private Button resetButton;
    private Button showMemoryButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_code);

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment()).commit();
        }

        memoryRecord = (EditText) findViewById(R.id.memoryEntry);

        saveButton = (Button) findViewById(R.id.save);
        resetButton = (Button) findViewById(R.id.reset);
        showMemoryButton = (Button) findViewById(R.id.showFile);


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main_code, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main_code,
                    container, false);
            return rootView;
        }
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

        if (v ==  resetButton){
            memoryRecord.getText().clear();

        }else if (v == showMemoryButton){
            showMemoryFile();
        }


    }

0 个答案:

没有答案