Newton Newton - 5 months ago 31
Android Question

Placing XML Code into layout, pager.xml

It seems as if I am getting errors for using

@color/background,
@color/primary_dark, and
@drawable/source_but.

Error:(32, 33) No resource found that matches the given name (at 'background' with value '@color/background').


Error:(44, 36) No resource found that matches the given name (at 'textColor' with value '@color/primary_dark').


Error:(121, 33) No resource found that matches the given name (at 'background' with value '@drawable/source_but').


I am creating a form inside of the source code of
https://developer.android.com/training/displaying-bitmaps/index.html

So basically I try to put the textboxes and other objects into:

image_detail_pager.xml under layout folder.

Here's how I try to place the objects:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background"
android:orientation="vertical"
tools:context="com.chalkstreet.learnandroid.main.Form">

<TextView
android:id="@+id/textViewHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:padding="10dp"
android:text="Fill the form and press the button to see the captured data."
android:textColor="@color/primary_dark"
android:textSize="16sp" />

<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"
android:ems="10"
android:hint="Name"
android:inputType="textPersonName"
android:textColor="#000000"
android:textColorHint="#f1434343" />

<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:ems="10"
android:hint="Email"
android:inputType="textEmailAddress"
android:textColor="#000000"
android:textColorHint="#f1434343" />

<EditText
android:id="@+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:ems="10"
android:hint="Password"
android:inputType="textPassword"
android:textColor="#000000"
android:textColorHint="#f1434343" />

<EditText
android:id="@+id/editText4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:ems="10"
android:hint="Phone"
android:inputType="phone"
android:textColor="#000000"
android:textColorHint="#f1434343" />

<Button
android:id="@+id/button_submit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="Submit" />

</LinearLayout>

<Button
android:id="@+id/buttonSrc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"

android:background="@drawable/source_but"
android:text="VIEW SOURCE CODE FOR ACTIVITY" />

</RelativeLayout>


.........................................................................

I have updated drawable with source_but.jpg, choosing my own image. And I updated colors.xml.
Now I have a different error! It seems something is inconsistent here.

Error:(34, 24) No resource found that matches the given name


(at 'label'

with value '@string/title_activity_form').

DisplayingBitmaps/Application/build/
intermediates/manifests/full/debug/AndroidManifest.xml


Error:Execution failed for task

':Application:processDebugResources'.

> com.android.ide.common.process.ProcessException:

org.gradle.process.internal.ExecException:

Process 'command 'Android/Sdk/build-tools/23.0.3/aapt''

finished with non-zero exit value 1


.......................................................................

Okay, I updated Strings.xml, my very last errors:

Here's my Form.java

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);
}
}


Here's the errors it gives me:

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

Answer

In your colors.xml file you need to define:

<color name="background">#FF0000</color>
<color name="primary_dark">#00FF00</color>

(Change the values with the colors that your want)


Then you need to add the file source_but to your drawable folder.
If it is an image just move it there.