android editTextが空かどうかを確認する方法は?
この例は、androideditTextが空かどうかを確認する方法を示しています。
ステップ1 − Android Studioで新しいプロジェクトを作成し、[ファイル]⇒[新しいプロジェクト]に移動して、新しいプロジェクトを作成するために必要なすべての詳細を入力します。
ステップ2 −次のコードをres / layout/activity_main.xmlに追加します。
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="https://schemas.android.com/apk/res/android" xmlns:tools="https://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <EditText android:id="@+id/editText" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:textSize="12sp" android:layout_marginTop="45dp"/> <Button android:id="@+id/buttonCheck" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Check Edit" android:layout_centerInParent="true" android:layout_marginTop="25sp" android:layout_below="@id/editText"/> </RelativeLayout>
ステップ3 −次のコードをsrc / MainActivity.java
に追加しますimport android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.text.TextUtils; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends AppCompatActivity { EditText editText; Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); editText = findViewById(R.id.editText); button = findViewById(R.id.buttonCheck); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (TextUtils.isEmpty(editText.getText().toString())){ Toast.makeText(MainActivity.this, "Empty field not allowed!", Toast.LENGTH_SHORT).show(); }else { Toast.makeText(MainActivity.this, "Proceed..", Toast.LENGTH_SHORT).show(); } } }); } }
ステップ4 −次のコードをandroidManifest.xmlに追加します
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="https://schemas.android.com/apk/res/android" package="app.com.sample"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
-
Androidでスクリーンタイムを確認する方法
スマートフォンは私たちの生活の非常に大きな部分を占めていますが、スマートフォンをじっと見つめている時間を見失いがちです。 幸い、AndroidでのスクリーンタイムはDigital Wellbeingアプリで確認できます。このアプリは、スマートフォンの合計使用量と個々のアプリでの滞在時間の両方を追跡します。 使用方法は次のとおりです。 Androidでスクリーンタイムを確認する DigitalWellbeingはAndroid9以降に組み込まれているアプリなので、追加のソフトウェアをインストールする必要はありません。 デジタルウェルビーイングとペアレンタルコントロールに移動して開始します
-
Android でバッテリーの状態を確認する方法
周りのほとんどのアイテムは、何らかの形のバッテリーを使用して機能します。バッテリーは、携帯電話からリモコンに至るまで、私たちの生活に欠かせないものになり、どこにでもあります。モバイルに関して言えば、リチウムイオン電池は長時間使用すると劣化します。バッテリーの劣化は避けられず、充電時間の不規則/延長、充電容量の低下、発熱の問題、排水不良、バッテリーの膨張などの形で明らかになります。バッテリーとデバイス自体の寿命を延ばすには、バッテリーの状態を定期的に監視することが重要です。そしてそれを適切に維持します。この記事では、貴重なハンドヘルド デバイスを最大限に活用できるように、オンラインで Andro