Round number float - double to int - long Java example
int nf = Math.round(5.789f);
System.out.print(nf); // 6
float f = 28.611f;
int n3 = Math.round(f);
System.out.println(n3); // 29
double d = 1234.56;
long lon = Math.round(d);
System.out.println(lon); // 1235
int diff = 90 - 40;
// float fDeleni = diff / 10; // error code
float fDeleni = (float)diff / 10.f; // ok
int nRound = Math.round(fDeleni);
// Caution:
int n2 = (int) 8.999f;
System.out.println(n2); // 8
396LW NO topic_id
AD
Další témata ....(Topics)
Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with `checkPermission`) or explicitly handle a potential `SecurityException`
try {
// your code for example:
// LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// Criteria criteria = new Criteria();
// provider = locationManager.getBestProvider(criteria, false);
// locationManager.requestLocationUpdates(provider, 400, 1, this);
} catch (SecurityException e) {
e.printStackTrace();
}
If your class extends AppCompatActivity
Check if linked appropriate library for:
Check if you have to properly sett SearchView in menu xml for onCreateOptionsMenu menu_main.xml
Check your SearchableActivity onCreateOptionsMenu
public class SearchableActivity extends AppCompatActivity
Check if linked appropriate library for:
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
Check if you have to properly sett SearchView in menu xml for onCreateOptionsMenu menu_main.xml
<menu xmlns:android="//schemas.android.com/apk/res/android" xmlns:app="//schemas.android.com/apk/res-auto"
xmlns:tools="//schemas.android.com/tools"
tools:context=".SearchableActivity">
<item
android:id="@+id/menu_search_my"
android:title="@string/menu_search"
android:icon="@drawable/ic_menu_search"
app:showAsAction="collapseActionView|ifRoom"
app:actionViewClass="android.support.v7.widget.SearchView"
/></menu>
Check your SearchableActivity onCreateOptionsMenu
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @SuppressLint("NewApi") @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
android.support.v7.widget.SearchView searchView = (android.support.v7.widget.SearchView)
MenuItemCompat.getActionView(menu.findItem(R.id.menu_search_my));
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
if(null!=searchManager ) {
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
}
searchView.setIconifiedByDefault(false);
}
return true;
}
main.xml
<LinearLayout xmlns:android="//schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="top"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:gravity="top"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imageViewObrazekGeometrie"
android:layout_width="360dp"
android:layout_height="777dp"
android:src="@drawable/geometrie_vzorecky" />
</LinearLayout>
</HorizontalScrollView>
</ScrollView>
</LinearLayout>
SeekBar setOnSeekBarChangeListener Example. Change TextView font size by SeekBar Example.
TextView mTextView01 = (TextView)findViewById(R.id.textView01);
SeekBar mSeekBarTexSize = (SeekBar)findViewById(R.id.seekBarTextSize);
mSeekBarTexSize.setMax(100);
mSeekBarTexSize.setProgress(25);
mSeekBarTexSize.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
mTextView01.setTextSize((float)progress);
}
public void onStartTrackingTouch(SeekBar seekBar) {}
public void onStopTrackingTouch(SeekBar seekBar) {}
});
If a button have focus, marquee will run.
Important:
android:singleLine="true"
android:ellipsize="marquee"
Optional:
android:marqueeRepeatLimit="1"
Important:
android:singleLine="true"
android:ellipsize="marquee"
Optional:
android:marqueeRepeatLimit="1"
// main.xml
<Button
android:layout_width="150dip"
android:layout_height="wrap_content"
android:text="My button with a long text for marquee as a example source code"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="1"/>
Editace: 2012-07-15 14:42:42
Počet článků v kategorii: 396
Url:round-number-float-to-int-java-example