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.

Titlebar title bar change text setTile Android example


Change the title associated with this activity. If this is a top-level activity, the title for its window will change. If it is an embedded activity, the parent can do whatever it wants with it.




 String sTitle = "My new title";
 setTitle(sTitle);




397LW NO topic_id



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


245

Cross Button in EditText Android | cross-button-in-edittext-android


Cross Button in EditText Android for deleting clearing text in EditText Example source code:
Example allow delete text in EditText by cross button, or do Button click performance.

main.xml type your package name and class
Put into drawable folder cross and ok image.

       <cz.okhelp.wiktionary.CustomEditText
            android:id="@+id/editTextZadejSlovo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:ems="10"
            android:hint="TypeAndPressGreen"
            android:singleLine="true"
            android:lines="1"
            android:maxLines="1" 
            android:drawableLeft="@drawable/cross"
            android:drawableRight="@drawable/ok" />
<!--button is invisible 0 height 0 width for performance click on button in EditText-->
        <Button
            android:id="@+id/btnGO"
            android:layout_width="0sp"
            android:layout_height="0sp"
            android:layout_weight="0"
            android:text="GO" />




CustomEditText.java

package cz.okhelp.wiktionary; // your package name

import android.content.Context;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.widget.Button;
import android.widget.EditText;

public class CustomEditText extends EditText
{
  private Drawable dLeft,dRight;
  private Rect lBounds,rBounds;
  private static Button btnOk;

  public CustomEditText(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
  }
  public CustomEditText(Context context, AttributeSet attrs) {
    super(context, attrs);
  }
  public CustomEditText(Context context) {
    super(context);
  }

  @Override
  public void setCompoundDrawables(Drawable left, Drawable top,
      Drawable right, Drawable bottom)
  {
   if(left !=null) {
    	dLeft = left;
    }
   if(right !=null){
      dRight = right;
    } 
    
    super.setCompoundDrawables(left, top, right, bottom);
  }

	@Override
	public boolean onKeyUp(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_ENTER) {
    	btnOk.requestFocus();
    	btnOk.performClick();

		}
		return super.onKeyUp(keyCode, event);
	}
  
  @Override
  public boolean onTouchEvent(MotionEvent event)
  {
  	final int x = (int)event.getX();
  	final int y = (int)event.getY();

  	if(event.getAction() == MotionEvent.ACTION_UP && dLeft!=null) {
  		lBounds = dLeft.getBounds();
  		
  		int n1 = this.getLeft();
  		int n2 = this.getLeft()+lBounds.width();
  		int n3 = this.getPaddingTop();
  		int n4 = this.getHeight()-this.getPaddingBottom();
  		// leva strana
  		if(    x>=(this.getLeft()) 
  				&& x<=(this.getLeft()+lBounds.width())
  				&& y>=this.getPaddingTop() 
  				&& y<=(this.getHeight()-this.getPaddingBottom()))
  		{
  			this.setText("");
  			event.setAction(MotionEvent.ACTION_CANCEL);//use this to prevent the keyboard from coming up
  		}
  	}
  	if(event.getAction() == MotionEvent.ACTION_UP && dRight!=null)
    {
      rBounds = dRight.getBounds();
      int n1 = this.getRight()-rBounds.width();
      int n2 = this.getRight()-this.getPaddingRight();
      int n3 = this.getPaddingTop();
      int n4 = this.getHeight()-this.getPaddingBottom();
      // prava strana
      if(x>=(this.getRight()-rBounds.width()) && x<=(this.getRight()-this.getPaddingRight())
      		&& y>=this.getPaddingTop() && y<=(this.getHeight()-this.getPaddingBottom()))
      {
      	btnOk.requestFocus();
      	btnOk.performClick();
      	event.setAction(MotionEvent.ACTION_CANCEL);//use this to prevent the keyboard from coming up
      }
    }
    
    return super.onTouchEvent(event);
  }

  @Override
  protected void finalize() throws Throwable
  {
    dRight = null;
    rBounds = null;
    super.finalize();
  }
	public void setBtnOk(Button btnOk) {
		this.btnOk = btnOk;
	}
	public Button getBtnOk() {
		return btnOk;
	}
}  



YourActivity.java

//onCreate
        Button  mBtnGO = (Button)findViewById(R.id.btnGO);
        CustomEditText mEditZadani = (CustomEditText)this.findViewById(R.id.editTextZadejSlovo);
        mEditZadani.setBtnOk(mBtnGO);
        mBtnGO.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
             // do stuff for signInButtonClick
          }
        });


//android.okhelp.cz/wiktionary-aplikace-pro-android/

wiktionary

318

Ad baner without GoogleAdMobAdsSdkAndroid-6.4.1 Android example | ad-baner-without-googleadmobadssdkandroid-6-4-1-android-example


First: AdView is in XML file

<com.google.android.gms.ads.AdView
    xmlns:ads="//schemas.android.com/apk/res-auto"
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    ads:adUnitId="MY_AD_UNIT_ID"
    ads:adSize="BANNER"/>

// onResume
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
    .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
    .addTestDevice("TEST_DEVICE_ID")
    .build();
adView.loadAd(adRequest);




Second: Using AdView in Fragment with LinearLayout
Resolve error in ADT Graphical layout editor:
The following classes could not be instantiated:
- com.google.android.gms.ads.AdView

// layout in xml file
    <LinearLayout
        android:id="@+id/layout"
              android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

// java class with fragment in Fragment class or in Activity class
private static AdView adView;
        @Override
		public void onResume(){  
                super.onResume();
                 try {
                	 // in xml is empty layout
					adView = new AdView(getActivity());
					adView.setAdUnitId("ca-app-pub-626/638103xxxxxxx");
					adView.setAdSize(AdSize.BANNER);  
					
                	                LinearLayout layout = (LinearLayout)getView() .findViewById(R.id.layout);
					layout.addView(adView);
					
					AdRequest adRequest = new AdRequest.Builder().build();   
					adView.loadAd(adRequest);

				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
        }


More about:
https://developers.google.com/mobile-ads-sdk/docs/admob/android/play-migration?hl=it
0

EditText text changed java Android | edittext-text-changed


Google Android example source code - is text changed in EditText ?

EditText hEditText;

// TextChanged in onCreate
hEditText = (EditText)findViewById(R.id.idEditText);
hEditText.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable str) {
}

public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}

public void onTextChanged(CharSequence sq, int start, int before,
int count) {
}
});
179

HTC Evo 4G | htc-evo-4g


HTC Evo 4G cena od 6 500 KCZ Kč (únor.2012)
HTC Evo 4G je chytrý telefon běžící na operačním systému Android.
HTC Evo 4G je (22.února2012) třetím nejpoužívanějším chytrým telefonem u programu Sky Map viz tabulka.

EVO je osazen čipsetem Qualcomm QSD8650, který obsahuje Snapdragon Scorpion mikroprocesor taktovaný na 1 GHz a integrovaný grafický čip Adreno 200.

Dále je vybaven 512 MB paměti eDRAM která umožňuje plynulejší běh s Android OS.


EVO má na zadní straně svítilnu, 8 megapixelový fotoaparát schopný nahrávání videa v rozlišení 720p při 30 snímcích za sekundu a duální blesk. EVO má 1,3 megapixelový fotoaparát i na přední straně zařízení, určený pro použití při videohovorech a pro vytvoření portrétních snímků.

Jako mnoho jiných mobilních zařízení s Androidem je i HTC EVO 4G vybaven slotem microSD kromě vestavěné paměti, který umožňuje uživateli rozšíření kapacity paměti. Přístroj podporuje paměťové karty microSD o velikosti až 32 GB. Android verze 2.2 + (Froyo) je k dispozici jako volně šiřitelný OS a může být stažen na SD kartu.

HTC Evo 4G photo pic image
samsung galaxy s2
Zdroj obrázku: wikipedia
89

Map TreeMap get key by value Java Android example | map-treemap-get-key-by-value-java-android-example


Get key by value from Map Java Android example


MainClass.java

import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;

public class MainClass {
	public static void main(String[] arg) {

		// english;germany dictionary
		String[] arrayOfString = { "one;eine", "two;zwei", "two sets of;zwei"
				, "three;drei", "four;vier" };

		Map<String, String> map = new TreeMap<String, String>();

		for (String s : arrayOfString) {
			String[] array = s.split(";");
			String sKey = "", sValue = "";
			if (array.length > 1) {
				sKey = array[0];
				sValue = array[1];
				map.put(sKey, sValue);
			}
		}

		if (map.containsValue("zwei")) {
			Set<String> references = getKeysByValue(map, "zwei");
			 Iterator<String> it = references.iterator();
			    while (it.hasNext()) {
			      String key = (String) it.next();
			      String value = map.get(key);
			      System.out.println(key + " = " + value);
			    }
		}

	}

	public static <T, E> Set<T> getKeysByValue(Map<T, E> map, E value) {
		Set<T> keys = new HashSet<T>();
		for (Entry<T, E> entry : map.entrySet()) {
			if (entry.getValue().equals(value)) {
				keys.add(entry.getKey());
			}
		}
		return keys;
	}
}
/*
two = zwei
two sets of = zwei
 */



Editace: 2011-09-17 12:34:02
Počet článků v kategorii: 397
Url:titlebar-title-bar-change-text-android-example
Share
Share
Tweet