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
Create a file called MainSource.java
, that is if you haven't done so already, and create a file called menu_main.xml
in the menu folder under the res directory and add your menu items, create another layout file in the layout folder under the res directory and name it activity_form.xml
, you can then add the necessary views with the ids matching those in Form.java
More illustratively, menu_main might contain
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never" />
</menu>
activity_form.xml could possibly be something like
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name" />
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email" />
<EditText
android:id="@+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Something Else" />
<EditText
android:id="@+id/editText4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Phone" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:id="@+id/button_submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/buttonSrc"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
I have no idea what you want MainSource to do so I can't say much about that. I hope this helps.