Get SensorManager PowerManager WindowManager Display Android example
private SensorManager mSensorManager;
private PowerManager mPowerManager;
private WindowManager mWindowManager;
private Display mDisplay;
// onCreate
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get an instance of the SensorManager
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
// Get an instance of the PowerManager
mPowerManager = (PowerManager) getSystemService(POWER_SERVICE);
// Get an instance of the WindowManager
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
mDisplay = mWindowManager.getDefaultDisplay();
setContentView(R.layout.main); // main.xml or your xml file name
}
396LW NO topic_id
AD
Další témata ....(Topics)
Foreach in Java basic example source code.
MainClass.java
MainClass.java
public class MainClass {
public static void main(String[] arg) {
String[] arrayOfString = { "Hello", "people", "hello", "world!" };
for (String s : arrayOfString)
System.out.println(s);
}
}
Adding TableRow with a View TextView (EditText Button) programmically dynamically to TableLayout Android sample basic example.
MainClass.java
main.xml
MainClass.java
public class MainClass extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TableLayout tl = (TableLayout)findViewById(R.id.tableLayout1);
TableRow row = new TableRow(this);
TextView tv = new TextView(this);
tv.setText("This is text");
tl.addView(row);
row.addView(tv);
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="//schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableLayout android:layout_width="fill_parent"
android:id="@+id/tableLayout1" android:layout_height="wrap_content">
</TableLayout>
</LinearLayout>
If you have to type frequently the same code you can create templates which can be activate via autocomplete with Ctrl + Space.
For example lets assume setOnClickListener body.
To create a template for this select the menu Window->Preferences and Open Java -> Editor -> Templates
[caption id="attachment_1114" align="alignleft" width="300" caption="Eclipse-show-template-proposals"][/caption]
[caption id="attachment_1116" align="alignleft" width="300" caption="Eclipse - select your template"][/caption]
Quick help in Eclipse editor: select keyword and press Ctrl+1
For example lets assume setOnClickListener body.
To create a template for this select the menu Window->Preferences and Open Java -> Editor -> Templates
Type name of template in Eclipse s editor and pres Ctrl+Space
[caption id="attachment_1114" align="alignleft" width="300" caption="Eclipse-show-template-proposals"][/caption]
Select your template from intellisense help and press Enter or double click on selected item.
[caption id="attachment_1116" align="alignleft" width="300" caption="Eclipse - select your template"][/caption]
mIdButtonHome.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("//android.okhelp.cz/category/software/"));
startActivity(browserIntent);
}
});
Quick help in Eclipse editor: select keyword and press Ctrl+1
Try two way in Eclipse IDE:
1.) Import the library project into your Eclipse workspace.
Click File > Import,
select Android > Existing Android Code into Workspace, and browse to the copy of the library project to import it.
If project not visible with checkbox try next step as see below.
2.) Click
File > New > Other
select Android > Existing Android Code into Workspace, and browse to the copy of the library project to import it.
1.) Import the library project into your Eclipse workspace.
Click File > Import,
select Android > Existing Android Code into Workspace, and browse to the copy of the library project to import it.
If project not visible with checkbox try next step as see below.
2.) Click
File > New > Other
select Android > Existing Android Code into Workspace, and browse to the copy of the library project to import it.
String[] sAr = new String[] {"one","two","three"};
List<String> wordList = Arrays.asList(sAr);
Collections.shuffle( wordList);
String[]myShuffledArray = wordList.toArray(new String[wordList.size()]);
Editace: 2011-11-07 11:43:11
Počet článků v kategorii: 396
Url:get-sensormanager-powermanager-windowmanager-display-android-example