Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

xml string with html tags Android


AD MOB


// in strings.xml
<string name="myStringWithTags"><![CDATA[<b>some text..</b> other tags ...]]></string>
<string name="myStringWithPattern"><![CDATA[<b>%s</b> other tags ...]]></string>
// in Activity.class
String sHtmlText = this.getApplicationContext().getString(R.string.myStringTags);
         sHtmlText = this.getApplicationContext().getString(R.string.myStringWithPattern,"replace %s with this text");

397LW NO topic_id




AD

Další témata ....(Topics)


23

Hide keyboard Android example | hide-keyboard-android-example


Use this code for example in some method or function

// public Object getSystemService (String name)
// Return the handle to a system-level service by name.
// The class of the returned object varies by the requested name.
InputMethodManager inputMethodManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
//public boolean hideSoftInputFromWindow (IBinder windowToken, int flags)
//EditText myEdit = (EditText)findViewById(R.id.idEditText);
inputMethodManager .hideSoftInputFromWindow(myEdit.getWindowToken(), 0);


283

Get Set Screen Orientation Android Code | get-set-screen-orientation-android-code



// in AndroidManifest.xml
<Activity
 android:screenOrientation="portrait" // or landscape

// in MyActivity.java
boolean mbOrientacionLandscape = false;
int nOrientation =	getResources().getConfiguration().orientation;
if(mbOrientacionLandscape==true){
	 getResources().getConfiguration();
	if(nOrientation != Configuration.ORIENTATION_LANDSCAPE)
	setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
	
}
else{
	if(nOrientation != Configuration.ORIENTATION_PORTRAIT)
	setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

241

Dialog With RadioButton Android Example | dialog-with-radiobutton-android-example



private void dialogModeFC() {
	try {
	final AlertDialog alertDialog =	new AlertDialog.Builder(MainActivity.this)
    .setTitle(R.string.select_dialog)
    //.setItems(
    .setSingleChoiceItems(R.array.select_dialog_items, -1
    		, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {

        /* User clicked so do some stuff 
        <item>Happy New Year</item>
        <item>Merry Christmas</item>
        <item>I Love You</item>
        */
            String[] items = getResources().getStringArray(R.array.select_dialog_items);
// list with boolean variables - which is true
//            for (int i = 0; i < _listMode.size(); i++) {
//            	_listMode.set(i, false);
//            }
//            _listMode.set(which, true);
            dialog.dismiss();
//            new AlertDialog.Builder(MainActivity.this)
//                    .setMessage("You selected: " + which + " , " + items[which])
//                    .show();
        }
    })
    .create();
	alertDialog.show();
	} catch (Exception e) {
		e.printStackTrace();
		Toast.makeText(getApplicationContext(), e.getMessage().toString(), Toast.LENGTH_LONG)
				.show();//("dialogModeFC", e.getMessage().toString());
	}
}// end dialogModeFC	
345

Pixel to density independent pixel to pixel conversion | pixel-to-density-independent-pixel-to-pixel-conversion


Physical pixel (px)
Density independent pixel (dp)
Dots per inch (dpi) .. physical pixels per inch
px = dp * (dpi / 160)

public static int dpToPx(int dp)
{
    return (int) (dp * Resources.getSystem().getDisplayMetrics().density);
}

public static int pxToDp(int px)
{
    return (int) (px / Resources.getSystem().getDisplayMetrics().density);
}
41

Preferences settings save open read write application Android example | preferences-settings-save-open-red-application-android-example


Android app setup preferences, settings, open, read, write, onStop(), onPause(), getSharedPreferences(), SharedPreferences.Editor getInt(), getBoolean(), getString() , putInt(), putString(), putBoolean() example source code.



import android.content.SharedPreferences;

public class MainClass extends Activity {
  public static final String PREFERENCES_NAME = "MyPrefsFile";
  String myNewString;
  int myNewInt;
  Boolean myNewBool;


   @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // read old settings if exist
      SharedPreferences settings = getSharedPreferences(PREFERENCES_NAME, 0);
			
     String sDefault = "Hello!";
      String sStringFromPrefFile = settings.getString("myString", sDefault); // new text  or default Hello!
          
      int nDefaultIndex = 2; //
      int nIndexFromPrefFile = settings.getInt("myInt", nDefaultIndex); // 4 or default 2
			
      Boolean bDefault = false;
      Boolean bFromPrefFile = settings.getBoolean("silentMode", bDefault); // true or default false
        
        
        // new settings will saved in onStop or onPause
        myNewString = "new text";
        myNewInt = 4;
        myNewBool = true;
     }   

    @Override
    protected void onPause() {
    	super.onPause();
        Toast.makeText(getApplicationContext(), "onPause "
        		, Toast.LENGTH_SHORT).show();

    	savePreferences();
    }
    
    @Override
    protected void onStop() {
    	super.onStop();
    	savePreferences();
    }
    /**save settings*/	
    public void savePreferences(){
    	try {
    		SharedPreferences settings = getSharedPreferences(PREFERENCES_NAME, 0);
    		SharedPreferences.Editor editor = settings.edit();
 
    		editor.putString("myString", myNewString);
     		editor.putInt("nMyInt", myNewInt);
    		editor.putBoolean("silentMode", myNewBool); // 
    		
    		editor.commit();
    	} catch (Exception e) {
    		// TODO Auto-generated catch block
    		e.printStackTrace();
    	}
    	
    }	
}


Editace: 2014-01-28 16:16:38
Počet článků v kategorii: 397
Url:xml-string-with-html-tags-android

AD
11 Share
Share
Tweet