Wednesday, 6 May 2020

radio button in android studio

                     Multi radio button in android studio with example 

                   <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:orientation="vertical">

                             <TextView
                              android:layout_width="match_parent"
                               android:layout_height="wrap_content"
                               android:layout_gravity="center"
                                android:textSize="@dimen/_16sdp"
                                android:textStyle="bold"
                                android:textColor="@color/colorPrimary"
                                android:text="Who are you here to see today?" />


                            <RadioGroup
                                android:layout_marginTop="@dimen/_10sdp"
                                android:id="@+id/radioGroup"
                                android:layout_width="fill_parent"
                                android:layout_height="wrap_content"
                                android:orientation="horizontal">

                                <RadioButton
                                    android:id="@+id/radioButton1"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:text="Dr. "
                                    android:textSize="18sp"/>

                                <RadioButton
                                    android:id="@+id/radioButton2"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:text=" Therapist."
                                    android:textSize="18sp"/>

                                <RadioButton
                                    android:id="@+id/radioButton3"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:text=" Or Both"
                                    android:textSize="18sp"/>
                            </RadioGroup>

                            </LinearLayout>

Android Time Picker Dialog with example

IN XML FILE

<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:layout_width="match_parent"
    android:background="@color/white"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".LoginActivity">

<TextView
android:id="@+id/pickuptime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_10sdp"
android:background="@drawable/gray_corner"
android:drawableLeft="@drawable/ic_access_time_black_24dp"
android:drawablePadding="@dimen/_10sdp"
android:focusable="true"
android:hint="time"
android:inputType="textEmailAddress"
android:isScrollContainer="true"
android:overScrollMode="always"
android:padding="@dimen/_10sdp"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
android:singleLine="false"
android:windowSoftInputMode="stateAlwaysVisible">
</TextView>
</LinearLayout>

In JAVA FILE


public class LoginActivity extends AppCompatActivity {
    TextView btn_login;
    TextView btnDate;
    TextView pickuptime;
    private int Year, Month, Day, mHour, mMinute;
    DatePickerDialog datePickerDialog;
    Calendar calendar;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        btn_login= findViewById(R.id.btn_login);
        pickuptime = findViewById(R.id.pickuptime);


pickuptime.setOnClickListener(new View.OnClickListener() {
    @Override    public void onClick(View v) {

        final java.util.Calendar c = java.util.Calendar.getInstance();
        mHour = c.get(java.util.Calendar.HOUR_OF_DAY);
        mMinute = c.get(java.util.Calendar.MINUTE);
 TimePickerDialog timePickerDialog = new TimePickerDialog(LoginActivity.this,
                new TimePickerDialog.OnTimeSetListener() {

                    @Override                    
public void onTimeSet(TimePicker view, int hourOfDay,
                                          int minute) {
                        //mStr_pickup_time= hourOfDay + ":" + minute;
pickuptime.setText(hourOfDay + ":" + minute);
                    }
                }, mHour, mMinute, false);
        timePickerDialog.show();

    }
});

Android Date Time Picker Dialog with example

Android Date Time Picker Dialog Project Code


create xml file in android studio 

for example : LoginActivity


<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:layout_width="match_parent"    
android:background="@color/white"    
android:layout_height="match_parent"    
android:orientation="vertical"    
tools:context=".LoginActivity">






<TextView    
android:id="@+id/btnDate"
android:layout_width="match_parent" 
android:layout_height="wrap_content"    
android:layout_marginTop="@dimen/_10sdp"    
android:background="@drawable/gray_corner"    
android:drawableLeft="@drawable/ic_date"    
android:drawablePadding="@dimen/_10sdp"    
android:focusable="true"    
android:hint="Date of Birth"    
android:inputType="textEmailAddress"    
android:isScrollContainer="true"    
android:overScrollMode="always"
android:padding="@dimen/_10sdp"    
android:scrollbarStyle="insideInset"    
android:scrollbars="vertical"
android:singleLine="false"
android:windowSoftInputMode="stateAlwaysVisible"></TextView>
</LinearLayout>
In Java file 
public class LoginActivity extends AppCompatActivity {
TextView btn_login;
TextView btnDate;
Button selectDate;
TextView date;
private int Year, Month, Day, mHour, mMinute;
DatePickerDialog datePickerDialog;
int year;
int month;
int dayOfMonth;
Calendar calendar;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
btnDate = findViewById(R.id.btnDate);
btnDate.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
final java.util.Calendar c = java.util.Calendar.getInstance();
int mYear = c.get(java.util.Calendar.YEAR); // current year
                int mMonth = c.get(java.util.Calendar.MONTH); // current month                
                int mDay = c.get(java.util.Calendar.DAY_OF_MONTH); // current day 
datePickerDialog = new DatePickerDialog(LoginActivity.this,
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
btnDate.setText(dayOfMonth + "-" + (monthOfYear + 1) + "-" + year);
}
}, mYear, mMonth, mDay);
datePickerDialog.getDatePicker().setMinDate(System.currentTimeMillis() - 1000);
datePickerDialog.show();
}
});
}
}

Tuesday, 5 May 2020

Card view in android Studio with example


How to use Card view in android Studio


use dependency for card view :

1) implementation "androidx.cardview:cardview:1.0.0"


<androidx.cardview.widget.CardView    android:layout_width="match_parent"    android:layout_height="wrap_content"
    android:orientation="horizontal"
    card_view:cardCornerRadius="2dp"
    card_view:contentPadding="10dp"
    card_view:cardElevation="30dp"
    app:cardBackgroundColor="@color/white">

</androidx.cardview.widget.CardView>

How to set on click Activity to Other Activity in android studio

set on click Activity to Other Activity  in android studio





btn_login= findViewById(R.id.btn_login);

findViewById(R.id.btn_login).setOnClickListener(new View.OnClickListener() {
    @Override    public void onClick(View view) {
        Intent intent = new Intent(LoginActivity.this, navigationActivity.class);
        startActivity(intent);
        finish();
    }
});

How to change Fragment to activity in Android Studio





change Fragment to activity in Android Studio






View view = inflater.inflate(R.layout.fragment_home, container, false);

shopdetails.setOnClickListener(new View.OnClickListener() {
    @Override    public void onClick(View v) {
        startActivity(new Intent(getActivity(), SalonDetailsActivity.class)

        );

    }
});