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.

Spinner ComboBox DropDown set on selected item listener setOnItemSelectedListener Java Android example


AD MOB

Spinner, ArrayAdapter, setOnItemSelectedListener, onItemSelected, setDropDownViewResource

MainClass.java

public class Vypocet extends Activity {
 Spinner   hSpinnerMetry;
// .......
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

	       hSpinnerMetry = (Spinner) findViewById(R.id.idSpinnerMetry);
	        ArrayAdapter<CharSequence> adapterMetry = ArrayAdapter.createFromResource(
	        		this, R.array.metry_array, android.R.layout.simple_spinner_item);
	        adapterMetry.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
	        hSpinnerMetry.setAdapter(adapterMetry);
			
	           hSpinnerMetry.setOnItemSelectedListener(
	                    new OnItemSelectedListener() {
	                        public void onItemSelected(
	                                AdapterView<?> parent, View view, int position, long id) {
	                        int nPos = position;
	                        }

	                        public void onNothingSelected(AdapterView<?> parent) {
	                        
	                        }
	                    });	        

      }
}



strings.xml


<string-array name="metry_array">
<item>m</item>
<item>dm</item>
<item>cm</item>
<item>mm</item>
</string-array>



397LW NO topic_id




AD

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


188

Error android.widget.LinearLayout.measureHorizontal LinearLayout.java | error-android-widget-linearlayout-measurehorizontal-linearlayout-java


Code with error:

ImageView imgV = (ImageView)findViewById(R.id.myView);
        imgV.setLayoutParams(new ViewGroup.LayoutParams(
        		ViewGroup.LayoutParams.WRAP_CONTENT,
        		0));


If you get error try this code:

        ViewGroup.LayoutParams layoutParams = imgV
				.getLayoutParams();
		layoutParams.height = 0;
		imgV.setLayoutParams(layoutParams);




java.lang.ClassCastException: android.view.ViewGroup$LayoutParams
at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:659)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:311)
at android.view.View.measure(View.java:8313)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:386)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
at android.view.View.measure(View.java:8313)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
at android.view.View.measure(View.java:8313)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:531)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
at android.view.View.measure(View.java:8313)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
at android.view.View.measure(View.java:8313)
254

Spinner Text Size Android Example | spinner-text-size-android-example



      Spinner  _spin1 = (Spinner) findViewById(R.id.spinLangFirst);
      ArrayAdapter<String> adapterJazyky = new ArrayAdapter<String>(this,
              R.layout.spinner_text_layout.xml, {"one","two","etc...."});
      adapterJazyky.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      _spin1.setAdapter(adapterJazyky);





spinner_text_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="//schemas.android.com/apk/res/android"
          android:id="@+id/spinnerText"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
         
         android:textSize="20sp"
/>
229

Which version of eclipse for android development | which-version-of-eclipse-for-android-development


I tried this Eclipse and work fine:
Eclipse Classic
//www.filehippo.com/download_eclipse_classic_32/

Eclipse Juno
Eclipse Helios

//developer.android.com/tools/sdk/eclipse-adt.html
261

Iterate over each Entry in Map Java Android | iterate-over-each-entry-in-map-java-android


entry put iterate Map HashMap Java Android

Map<String, Integer> map = new HashMap<String, Integer>();
map.put("key27", 27);
for (Map.Entry<String, Integer> entry : map.entrySet())
{
 String str = entry.getKey();
 int n = entry.getValue();
}
15

int java android example | int-java-android-example


int occupy 4 bytes (32 bits) in memory

int in Java example of using Integer and Array of Integer and Iteger to String

        // get max end min values of int in Java example 4 bytes (32 bits) PC architecture
	System.out.println(Integer.MAX_VALUE); // 2147483647
	System.out.println(Integer.MIN_VALUE); // -2147483648


// members variable
private int mProgress = 10;

//integer to string java
int myInteger = 8;
String myString = Integer.toString(myInteger);

// a final variable can only be initialized once
static final int NUM_PARTICLES = 15;

 for (int i = 0; i < NUM_PARTICLES ; i++) { 
// do something
}

// int as return value of function
public int getCount() {
return 5;
}

// int as a parametr of function
public float getFloatFromInt(int i) {
float fRet = (float) i;
 return fRet;
}

//array of int
int[] anArray;              // declares an array of integers
          anArray = new int[2];      // allocates memory for 2 integers
          anArray[0] = 100; // initialize first element
          anArray[1] = 200; // initialize second element

for (int i = 0; i < anArray.length; i++) {
// print out values from anArray
System.out.println("Index: " + i);
System.out.println("Value: " + anArray[i]); 
}




Editace: 2011-09-19 07:36:08
Počet článků v kategorii: 397
Url:spinner-combobox-set-on-selected-item-listener-setonitemselectedlistener-java-android-example

AD
11 Share
Share
Tweet