Making form on android studio

Amadeus picture Amadeus · Jun 13, 2016 · Viewed 15.4k times · Source

I took some code to make a simple Form on Android. It seems as if some parts of the code are referencing to something. I'm not sure what to put there to make it work? I get errors.

Error:(18, 32) error: cannot find symbol variable activity_form
Error:(33, 88) error: package com.chalkstreet.learnandroid.main does not exist
Error:(48, 50) error: cannot find symbol class MainSource
Error:(57, 41) error: cannot find symbol variable menu_main

I don't think that I need to be using the package that I am not having.

Example problem:

Intent sender = new Intent(Form.this, 
===> ????  com.chalkstreet.learnandroid.main.Display.class);

Here's my form:

public class Form extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_form);
    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    //Initialize buttons and Edit Texts for form
    Button btnSubmit = (Button) findViewById(R.id.button_submit);
    Button btnSrc = (Button) findViewById(R.id.buttonSrc);
    final EditText name = (EditText) findViewById(R.id.editText1);
    final EditText email = (EditText) findViewById(R.id.editText2);
    final EditText phone = (EditText) findViewById(R.id.editText4);

    //Listener on Submit button
    btnSubmit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent sender = new Intent(Form.this, com.chalkstreet.learnandroid.main.Display.class);
            Bundle b1 = new Bundle(); //Bundle to wrap all data
            b1.putString("name", name.getText().toString()); //Adding data to bundle
            b1.putString("email", email.getText().toString());
            b1.putString("phone", phone.getText().toString());
            sender.putExtras(b1); //putExtras method to send the bundle
            startActivity(sender);
            Form.this.finish(); //Finish form activity to remove it from stack
        }
    });

    //Listener on source button
    btnSrc.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent j = new Intent(Form.this, MainSource.class);
            startActivity(j);
        }
    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == android.R.id.home) {

        Form.this.finish();
        return true;
    }
    return super.onOptionsItemSelected(item);


 }
}

Thanks

Answer

Alexandre Martin picture Alexandre Martin · Jun 13, 2016

When you create an explicit Intent, you only need to provide the starting context and the ending class.

Intent i = new Intent(FirstActivity.this, ResultActivity.class);