I am learning android from Android Tutorial for Beginners 8 # wrap_content, fill_parent, Password Field and Toast in Android
using android studio 2.2.2.
I have done the same as mentioned in tutorial but unable to understand why getApplicationContext() and getActivity methods are not resolvable.
I have tried getActivity(), getActivity().getApplicationContext(), MainActivity.this.... etc. But Toast.makeText method unable to recognize Context.
Can anyone please tell me what is the exact issue? and how can I resolve it?
Below is my code:
package com.example.programingknowledge.myfirstapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private EditText pass_word;
private Button btn_sbm;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
}
public void addListenerOnButton() {
pass_word = (EditText) findViewById(R.id.editText);
btn_sbm = (Button) findViewById(R.id.button);
final CharSequence passText = pass_word.getText().toString();
btn_sbm.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), passText, Toast.LENGTH_SHORT).show();
}
});
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.programingknowledge.myfirstapp">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.programingknowledge.myfirstapp.MainActivity"
android:background="#android:color/black">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/editText" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="23dp"
android:id="#+id/button"
android:layout_below="#+id/editText"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Just change getApplicationContext() or getContext() to YourActivity.this
For example
Toast.makeText(MainActivity.this, passText, Toast.LENGTH_SHORT).show();
Please do not store context as a field. You are able to get in from any point, without storing.
When you are in Activity that means you have the Context i.e. the Activity. You can achieve this by calling this or MainActivity.this. As you are using the Toast inside the OnClickListener object this will not work here because here this means it will take OnClickLister as its object. So here you must use your class.this i.e MainActivity.this.
In case of Fragment you can achieve context by Calling getActivity() because Fragment must have at least a Activity which is the Context.
And the getApplicationContext() means your whole Application Context.
btn_sbm.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, passText, Toast.LENGTH_SHORT).show();
}
});
In your case, you're trying to show a toast from a callback. You should pass the MainActivity.this as context in the makeToast method:
Toast.makeText(MainActivity.this, passText, Toast.LENGTH_SHORT).show();
btn_sbm.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), passText, Toast.LENGTH_SHORT).show();
}
});
Try this
Please, post your AndroidManifest.xml and activity_main.xml files.
Upd.: The problem is that in your app's build.gradle file was compileSdkVersion 25, but you don't download it. Also you should always download android-sdk sources according to your targetSdkversion. So, just keep your Android Studio files current and that problems should go away.
Toast.makeText(MainActivity.this, passText, Toast.LENGTH_SHORT).show();
The above should work. If not, post your Logcat for the crash.
Related
Please help me sorting out where I am wrong. Because when I start a new activity using a button click the app crashes.
I am unable to figure out. I used another Acitvity from the same application and it launched successfully. But this nelwy created activity isn't starting in any ways.
My codes are:
[secondscreen.java]
package org......android.activities;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import org......android.R;
public class secondscreen extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_secondscreen);
TextView myAwesomeTextView = (TextView)findViewById(R.id.myAwesomeTextView);
myAwesomeTextView.setText("brown fox");
}
}
[activity_secondscreen.xml]
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.secondscreen">
<TextView
android:id="#+id/myAwesomeTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="secondscreen activity"
android:textSize="34sp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
[starting activity code in a first activity]
buttonTraining = findViewById(R.id.buttonTraining);
buttonTraining.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(),"going to second activity...",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getApplicationContext(),secondscreen.class);
startActivity(intent);
}
});
[partial stacktrace]
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
Worked. After Changed
From
<activity
android:name=".activities.secondscreen"
android:exported="false"/>
to
<activity
android:name=".activities.secondscreen"
android:exported="false"
android:theme="#style/Theme.AppCompat.Light.NoActionBar"/>
I'm brand new to Android Studio and for whatever reason am experiencing really weird errors if I could please get some help.
I have very basic code that is supposed to, on button click change the text of my button from "button" to "clicked!". However everytime I press the button, the app crashes and I get "Appname has stopped" on the emulator.
What is incredibly weird is that in my activity_main.xml Design view, the onClick dropdown shows two functions of the same name (https://puu.sh/t2h5I/42ad4379d6.png)
H owever the code only works when the bottom one is selected. AND each time I run the app, it deselects the bottom one and reselects the top, only to stop working.
Here is my MainActivity:
package com.example.john.ameladay;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
public Button melButtonCode;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void buttonPress(View v){
melButtonCode = (Button) v;
((Button) v).setText("Has been clicked!");
}
}
Here is my activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.john.ameladay.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/mainText"
android:id="#+id/textView" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/mela"
android:id="#+id/melPhoto" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/textView"
android:layout_toEndOf="#+id/textView"
android:layout_marginLeft="32dp"
android:layout_marginStart="32dp"
android:layout_marginBottom="43dp"
android:id="#+id/button"
android:onClick="buttonPress (MainActivity)" />
Any help would be greatly appreciated!!
Simple. You should write:
android:onClick="buttonPress"
Why happened
If you wrote buttonPress (MainActivity), Android tries to find buttonPress (MainActivity) method (not MainActivity.buttonPress()), but MainActivity doesn't have buttonPress (MainActivity) method. So the error happened.
Simply replace this Tag in button
Remove this
android:onClick="buttonPress (MainActivity)"
And Paste This
android:onClick="buttonPress"
A better way to do it is, get a reference to the button in your Java code using findViewById() method and set an OnClickListener to the button.
For your current problem, use
android:onClick="buttonPress"
instead of
android:onClick="buttonPress (MainActivity)"
According to me this is the better way to set click on button
public class MainActivity extends AppCompatActivity {
public Button melButtonCode;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
melButtonCode = (Button).findViewById(R.id.button);//find button by Id
melButtonCode.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
melButtonCode.setText("Has been clicked!");
}
});
}
}
For your problem
replace it
android:onClick="buttonPress (MainActivity)"
With
android:onClick="buttonPress"
Make the method public - protected works when you are in instantrun mode, but not when not. No idea why!
Here are my files (Conversion.xml, Conversion.java and AndroidManifest.xml). It is a small part of a project. I am able to get to the screen where I want to convert the power in watts to decibels. But when I enter the power value and click the button "Convert", the app crashes and goes back to the my app home screen.
conversion.xml
<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="match_parent"
android:orientation="vertical"
tools:context=".ConvertTodB" >
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Enter the power in Watts"
android:inputType="number"
android:text="#string/et1" />
<Button
android:id="#+id/bConvert"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Convert" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Result in dB"
android:text="#string/et2"
android:textSize="20sp"/>
</LinearLayout>
Conversion.java
package com.example.rfconcepts;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.lang.Math;
public class Conversion extends Activity {
EditText entered_val;
TextView result_val;
Button bCon;
#Override
protected void onCreate(Bundle convertTodB) {
super.onCreate(convertTodB);
setContentView(R.layout.conversion);
entered_val = (EditText) findViewById(R.string.et1);
bCon = (Button) findViewById(R.id.bConvert);
result_val = (TextView) findViewById(R.string.et2);
bCon.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(entered_val.getText() != null && entered_val.getText().length() != 0){
result_val.setText(String.valueOf(10 * Math.log10(Double
.valueOf(entered_val.getText().toString()))));
}
}
});
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.rfconcepts"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.rfconcepts.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.rfconcepts.Conversion"
android:label="#string/app_name">
</activity>
</application>
</manifest>
I thank you in advance for the advise.
P.S:
Here is a list of things I did after reading a lot of solutions for various questions posted here.
Instead of using onClickListener, in conversion.xml, i added the attribute "android:onClick = "onClickConvert" and added the follwoing onClickConvert method in the Activity class.
public void onClickConvert(View v){
if(entered_val.getText() != null && entered_val.getText().length() != 0){
result_val.setText(String.valueOf(10 * Math.log10(Double
.valueOf(entered_val.getText().toString()))));
}
}
Changed Double.parseDouble() to Double.valueOf() (Although, I do not think this is the issue)
Checked if the editText itself has null, hence the if statement.
entered_val = (EditText) findViewById(R.string.et1);
Why are you referring to a string? It should be an ID.
You did not declare an ID for your EditTexts. Do something like this:
<EditText
[...]
android:id="#+id/MyEditText"
/>
Then you can refer to it like this:
entered_val = (EditText) findViewById(R.Id.MyEditText);
Also do the same with your TextView.
Second issue:
EditText.getText() returns an Editable, but you need a String. Convert it like this:
if(entered_val.getText().toString() != null && entered_val.getText().toString().length() != 0
You shall an ID in EditText of your conversion.xml and then access it in Java code. Post your logcat error for more concrete answer
you need to add reference id to the EDITTEXT in power and result
<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="match_parent"
android:orientation="vertical"
tools:context=".ConvertTodB" >
<EditText
android:id="#+id/et1" // add the reference id
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Enter the power in Watts"
android:inputType="number"
android:text="#string/et1" />
<Button
android:id="#+id/bConvert"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Convert" />
<TextView
android:id="#+id/et2"// add the reference id
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Result in dB"
android:text="#string/et2"
android:textSize="20sp"/>
Also wired up those edittext with referenceid in your java code
entered_val = (EditText) findViewById(R.id.et1); // wired up with the xml id of the component
bCon = (Button) findViewById(R.id.bConvert);
result_val = (TextView) findViewById(R.id.et2);// wired up with the xml id of the component
I am doing the simplest of onClick models and cannot get the onClick method to fire. I know it is something simple, and I am new to Android. Any help is appreciated.
package com.bordeloniphone.timeentry;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class TimeEntryActivity extends Activity implements OnClickListener{
/** Called when the activity is first created. */
Button okButton;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
okButton = (Button) findViewById(R.id.btnOK);
okButton.setText(":)");
okButton.setOnClickListener(this);
//setContentView(okButton);
}
public void onClick(View v) {
Log.d("TEST", "TEST");
Toast.makeText(this, "TEST", Toast.LENGTH_SHORT).show();
}
}
Here is the main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/btnOK"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:text="OK" />
</LinearLayout>
After much angst and gnashing of teeth, I figured it out. I had to delete the emulator device and add an new one and now it works like a champ. I appreciate everyone trying to help.
Instead of setting the onClicklistener to this, try this approach:
okButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Log.d("TEST", "TEST");
Toast.makeText(this, "TEST", Toast.LENGTH_SHORT).show();
}
});
You should try Cleaning your project or try to restart your Eclipse or any other Editor you are using as it is a valid code and should work fine.
UPDATE:
Also, you should check your Logcat, are you getting the output of Log.d("TEST", "TEST"); because your Toast seems to be implemented in a wrong manner.
Toast.makeText(this, "TEST", Toast.LENGTH_SHORT).show(); // wrong
Toast.makeText(Activity_name.this, "TEST", Toast.LENGTH_SHORT).show(); // correct
Using this in Toast inside the Listener means you are Referencing the Listener, which indeed should not be the case. You have to reference to the Activity itself so better use Activity_name.this.
Button iv_StyleInspiration_Back = (Button) findViewById(R.id.iv_StyleInspiration_Back);
iv_StyleInspiration_Back.setOnClickListener(this);
Try this Whenever you implement onclick in your activity you need to set as above to make it work for all controls and onclick should look something as below
#Override
public void onClick(View pView) {
if (null != pView) {
switch (pView.getId()) {
case R.id.iv_StyleInspiration_Back:
//do what you want
break;
default:
break;
}
}
}
Check for Three Steps:
find the button by id correctly
link the button to a listener. (adding the actionListener)
you specify a condition for this button in case of implementing an actionListener class.
try making the button clickable
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/btnOK"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:text="OK"
android:clickable="true" />
GET EDITTEXT INPUT TO TEXTVIEW IN ANOTHER CLASS USING A BUTTON
I am fairly new to android and I am trying to use an edittext to get user input on one screen (Activity), actually not just one edittext a few like a couple edit texts and maybe a spinner, kind of like a create a new user screen. But I know how to use a button to getText() and setText() from the edittext to the textview if they are in the same activity but can not find anywhere how to accomplish this. Here is something like what the first class's bare bones would be:
public class UserInput extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EditText edit = (EditText) findViewById(R.id.editText1);
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
}
}
Now I know the magic will be in the onClick(View v){} method, but what magic exactly do I use to 1-open a new Activity that houses the textview and 2- open the Activity?
Here is the second Activity for visual reference:
public class GetText extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
TextView view = (TextView) findViewById(R.id.textView1);
}
}
Again please if anyone can even chop up the code I will use just trying to get it to work right now. Hopefully everyone can rally and give their input as to help others out that may be stuck as well. Thanks ahead of time.
Here is what I have and if force closes on me:
Main Activity:
package com.mandam.ok;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class UserInput extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EditText edit = (EditText) findViewById(R.id.editText1);
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
EditText edit = (EditText)
findViewById(R.id.editText1);
Intent intent = new Intent(UserInput.this, GetText.class);
intent.putExtra("com.mandam.ok.GETTEXT",
edit.getText().toString());
startActivity(intent);
}
});
}
}
Second Activity:
package com.mandam.ok;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class GetText extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
TextView view = (TextView) findViewById(R.id.textView1);
Intent intent = getIntent();
String name = intent.getStringExtra("com.mandam.ok.MAIN");
//edit.setText(view.getText());
}
}
I will even attach my xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello" />
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
Second xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
And manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mandam.ok"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name=".OkActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="#string/app_name"
android:name=".GetText" >
<intent-filter >
<action android:name="com.mandam.ok.GETTEXT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Now I know I am missing something very simple, just don't know what. I appreciate the help so far. :)
Your second activity HAS a textview... saying that it IS a textview is wrong since Activities are not Views.
Here's how you can pass arguments to a new Activity... this code would be in your first Activity's onClick:
EditText edit = (EditText) findViewById(R.id.editText1);
Intent intent = new Intent(UserInput.this, GetText.class);
intent.putExtra("com.package.name.NAME", edit.getText().toString());
startActivity(intent);
where "com.package.name" is your package name. An intent is an abstraction that performs an operation. In this case, the intent tells android to create a new Activity. The putExtra method allows you to put extra information into the intent before telling Android to create a new Activity. When you put an extra variable into an intent, you need to give it a unique string identifier that preferably starts with the package name.
Once the other Activity is created, here's how you can retrieve the string:
Intent intent = getIntent();
String name = intent.getStringExtra("com.package.name.NAME");
// do whatever you want with name