postheadericon How to access Resource String in Android



MainActivity.java

package com.example.r_stringdemo;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;


public class MainActivity extends Activity {

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

String nm=getApplicationContext().getString(R.string.un);
if(nm.equals("bipin"))
{
Toast.makeText(getApplicationContext(), "True", Toast.LENGTH_LONG).show();
}
}
}




res/values/strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">R_StringDemo</string>
    <string name="hello_world">Hello world!</string>
    <string name="menu_settings">Settings</string>
    <string name="un">bipin</string>

</resources>


0 comments:

Follow by Email

Total Pageviews

© BipinRupadiya.com. Powered by Blogger.