article

Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Sunday, December 19, 2021

Android Java Dialog Box App Version Name and Version Code

Android Java Dialog Box App Version Name and Version Code

app/src/main/res/layout/activity_main.xml
 
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"
    tools:context=".MainActivity">

    <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/dialogbox"
        android:textSize="24sp" tools:text="Dialog Box" tools:textAlignment="center" />

    <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="bottom"
        android:orientation="vertical">

        <Button android:id="@+id/btnabout" android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal" android:text="@string/aboutapp" />
    </LinearLayout>
</LinearLayout>
app/src/main/java/com/myappdev/MainActivity.Java
 
package com.myappdev;

import androidx.appcompat.app.AppCompatActivity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button buttonAboutMe = (Button)findViewById(R.id.btnabout);

        buttonAboutMe.setOnClickListener(new Button.OnClickListener(){

            @Override
            public void onClick(View v) {

                String strVersion;

                PackageInfo packageInfo;
                try {
                    packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
                    strVersion = "Version Name: " + packageInfo.versionName +"\n"
                            + "Version Code: " + String.valueOf(packageInfo.versionCode);
                } catch (NameNotFoundException e) {
                    e.printStackTrace();
                    strVersion = "Cannot load Version!";
                }

                new AlertDialog.Builder(MainActivity.this)
                        .setTitle("About The App!").setMessage(strVersion)
                        .setPositiveButton("OK",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {}
                                }).show();
            }
        });
    }
}
app/src/main/res/value/strings.xml
 
<resources>
    <string name="app_name">MyappDev</string>
    <string name="app_first_started">App first started</string>
    <string name="aboutapp">- About -</string>
    <string name="dialogbox">Dialog Box</string>
</resources>

Android Java AutoCompleteTextView

Android Java AutoCompleteTextView

App/src/main/res/layout/activity_main.xml
 
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Android Java MultiAutoCompleteTextView"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <MultiAutoCompleteTextView android:id="@+id/multiautocompletetextview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:completionThreshold="1"
        />
</LinearLayout>
app/src/main/java/com/myappdev/MainActivity.Java
 
package com.myappdev;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.MultiAutoCompleteTextView;

public class MainActivity extends AppCompatActivity {

    MultiAutoCompleteTextView myMultiAutoCompleteTextView;
    String item[]={
            "January", "February", "March", "April",
            "May", "June", "July", "August",
            "September", "October", "November", "December"
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        MultiAutoCompleteTextView myMultiAutoCompleteTextView
                = (MultiAutoCompleteTextView)findViewById(
                R.id.multiautocompletetextview);

        myMultiAutoCompleteTextView.setAdapter(
                new ArrayAdapter<String>(this,
                        android.R.layout.simple_dropdown_item_1line, item));
        myMultiAutoCompleteTextView.setTokenizer(
                new MultiAutoCompleteTextView.CommaTokenizer());
    }
}

Thursday, September 23, 2021

How to fix Mac M1 Your CPU Does Not Support VT-x

How to fix Mac M1 Your CPU Does Not Support VT-x

Related Post