Saturday, December 11, 2021

Date Picker With Dialog box

 xml :-

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Select Date"
android:id="@+id/tvDate"
android:layout_marginTop="50dp"
android:layout_centerHorizontal="true"
android:textSize="30sp"/>

Java :- 
private TextView mDisplayDate;
private DatePickerDialog.OnDateSetListener mDateSetListener;


under oncreate 


mDisplayDate = (TextView) findViewById(R.id.tvDate);

mDisplayDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DAY_OF_MONTH);

DatePickerDialog dialog = new DatePickerDialog(
Appoinment.this,
android.R.style.Theme_Holo_Light_Dialog_MinWidth,
mDateSetListener,
year,month,day);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
}
});

mDateSetListener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int year, int month, int day) {
month = month + 1;
Log.d(TAG, "onDateSet: mm/dd/yyy: " + month + "/" + day + "/" + year);

String date = month + "/" + day + "/" + year;
mDisplayDate.setText(date);
}
};

Current Time show in android

 Xml:-

<TextView
android:layout_width="match_parent"
android:textSize="20dp"
android:id="@+id/date"
android:layout_height="wrap_content"
android:text="hello world" />








Java :- 

Thread t = new Thread() {
@Override
public void run() {
try {
while (!isInterrupted()) {
Thread.sleep(1000);
runOnUiThread(new Runnable() {
@Override
public void run() {
TextView tdate = (TextView) findViewById(R.id.date);
long date = System.currentTimeMillis();
SimpleDateFormat sdf = new SimpleDateFormat("MMM dd yyyy\nhh-mm-ss a");
String dateString = sdf.format(date);
tdate.setText(dateString);
}
});
}
} catch (InterruptedException e) {
}
}
};
t.start();

Spineer View

 XML Code :- 

<Spinner
android:id="@+id/spineer"
android:layout_width="match_parent"
android:layout_height="50dp"
/>

->Value file-> Srting file  ->
<string-array name="covid">
<item>Covid Test</item>
<item>Covid vaccine</item>
</string-array>



Java :- 


package com.niranjan.covid19apps.user;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

import com.niranjan.covid19apps.R;

public class Appoinment extends AppCompatActivity implements AdapterView.OnItemSelectedListener{

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_appoinment);
Spinner spinner=findViewById(R.id.spineer);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,R.array.covid, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
}


@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
String text = adapterView.getItemAtPosition(i).toString();
Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
}

@Override
public void onNothingSelected(AdapterView<?> adapterView) {

}
}

Monday, December 6, 2021

SQLite Database Code

 http://www.codebind.com/android-tutorials-and-examples/android-sqlite-tutorial-example/

Activity Navigation One Activity to another Activity

Main Activity :-   <? xml version ="1.0" encoding ="utf-8" ?> < RelativeLayout xmlns: android ="http://sch...