I've been diving into native Android application development with Android Studio lately. It went quite well, thanks to lots of available tutorials and large community on Stackoverflow.
As a result of last 2 weeks I've created this gist with links and code snippets for Android development that will hopefully help you to bootstrap.
Button linkBtn = (Button) findViewById(R.id.button_toast);
linkBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(GolfcourseDetailActivity.this, "Here's your toast!",
Toast.LENGTH_LONG).show();
}
});
builder = new AlertDialog.Builder(this);
//Setting message manually and performing action on button click
builder.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//seems to close the app!!
finish();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'NO' Button
dialog.cancel();
}
});
AlertDialog alert = builder.create();
//Setting the title manually
//alert.setTitle(title);
//alert.setMessage(message);
alert.show();
attribute: android:background="@drawable/ID_OF_IMAGE"
- in XML -
android:label="@strings/my_activity_label"
- in JAVA -
setTitle("Hello StackOverflow")
;
Using drawables; first declare in res/drawables, then use in layout:
```
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:layout_centerHorizontal="true"
android:src="@drawable/ID_OF_THE_DRAWABLE"/>
```
```
getActionBar().setDisplayHomeAsUpEnabled(true);
```
Add html/css to assets, then use it in the activity:
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("file:///android_asset/components_webpage.html");
"However the TextView is referenced, it will be filled with the toString() of each object in the array. You can add lists or arrays of custom objects. Override the toString() method of your objects to determine what text will be displayed for the item in the list."
- You need ArrayAdapter and custom data type Class, see How to use ArrayAdapter
- Then reasoning from here - theopentutorials.com
In Java class:
public void openListActivity (View v) {
Intent intent = new Intent(this, MY_ACTIVITY_CLASS_NAME.class);
startActivity(intent);
}
then in the layout XML:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Back to list"
android:id="@+id/button3"
android:onClick="openListActivity"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
- see:
build.gradle
- Gradle and build process
- Put messages to log:
Log.d("MY_ACTIVITY_NAME", "opening state...");
In Java class
private void goToUrl (String url) {
Uri uriUrl = Uri.parse(url);
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(launchBrowser);
}
private void goToSu () {
String addres = "http://stackoverflow.com/";
goToUrl(addres);
}
```
then in layout template:
```
- How to call json API in JAVA - Android app Volley or Retrofit
- Use SQLite, then inspect change though ADM
- Use SharedPreferences (get/set via Editor)
SharedPreferences pref = getApplicationContext().getSharedPreferences(SAVE_PREF_ID, MODE_PRIVATE);
SharedPreferences.Editor sp = pref.edit();
sp.putString(SAVE_KEY_NAME, title);
//..
sp.apply();
- API levels
- Styles generator
- Make activity as a default, add to Maniseft file, in selected activity definition
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
- https://developer.android.com/samples/index.html
- http://mobileappdocs.com/android.html
- http://guides.codepath.com/android/Architecture-of-Android-Apps
- https://github.com/googlesamples/android-architecture
- https://github.com/googlesamples/android-architecture/tree/todo-mvp-loaders/
- https://github.com/dmilicic/Android-Clean-Boilerplate
This comment has been removed by a blog administrator.
ReplyDelete