public String f_dateFormat(String cdate, String dateToFormat) {
// String cdate = "2013-05-15T10:00:00-0700";
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
Date date = null;
try {
date = dateFormat.parse(cdate);
} catch (ParseException e) {
e.printStackTrace();
}
DateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
String sdate = df.format(date);
//now you can use Date class function i.e.
//date.getDay();
//date.getMonth();
//date.getYear();
return sdate;
}
Thursday, December 16, 2021
Date format in android
Thursday, December 9, 2021
Read only
1. Read only or not editable
android:editable="false"
<EditText
android:id="@+id/et_test_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginTop="40dp"
android:hint="ID"
android:textSize="20sp"
android:editable="false"
/>
DropDownList
1. DropDownList in android studio
<Spinner
android:id="@+id/spinner1"
android:layout_width="253dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="sss"
android:minHeight="48dp"
android:padding="8dp" />
Equal size in xml
1. Fix equal size or equal width in xml
android:layout_weight="1"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context=".MainActivity">
<Button
android:id="@+id/idBtnPost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="Save"
android:layout_weight="1"
android:textAllCaps="false" />
<Button
android:id="@+id/btn_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="Go Back"
android:layout_weight="1"
android:textAllCaps="false" />
</LinearLayout>
Monday, December 6, 2021
Set Images
1. Button in fragment
android:drawableLeft="@drawable/ic_baseline_search_24"
<Button
android:id="@+id/btn_search"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_weight="1"
android:contentDescription="Search"
android:drawableLeft="@drawable/ic_baseline_search_24"
app:layout_constraintBaseline_toBaselineOf="@+id/et_name"
app:layout_constraintEnd_toStartOf="@+id/progressBar1" />
2. Image Button in fragment
android:src="@drawable/ic_baseline_close_24"
<ImageButton
android:id="@+id/imgBtn_from"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:contentDescription="From Date Cancel"
android:minWidth="48dp"
android:minHeight="48dp"
android:padding="0dp"
android:src="@drawable/ic_baseline_close_24" />
Sunday, December 5, 2021
Region
In Java
In C#
#region regionNameprivate int myVaribale;private String otherVariblae;#endregion
Transfer data one fragment to another With Cunstructor
B.1. Send data from This Fragment (Source Fragment)
public class testList extends Fragment {
//Define Event Listener
private TestFragmentEvent listener;public interface TestFragmentEvent {
public void TestFragmentEvent_Create();
public void TestFragmentEvent_View(String data);}public void onAttach(@NonNull Context context) {
super.onAttach(context);
if (context instanceof SecondFragment.onFrgmtSecondBtnSelected) {
listener = (TestFragmentEvent) context;
} else {
throw new ClassCastException(context.toString() + " must implement listener");
}}
public void f_showData() {String rdata = "{Id:101,Name:"XYZabc"}";
try {
rdata = testDataJsonArray.getJSONObject(i).toString();
} catch (JSONException e) {
e.printStackTrace();
}
listener.TestFragmentEvent_View(rdata);}}
B.2 Main Activity
public class MainActivity extends AppCompatActivity implements testList.TestFragmentEvent {@Override
public void TestFragmentEvent_View(String data) {
testView testview = new testView(data);
fragmentManager = getSupportFragmentManager();
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.container_fragment, testview);
fragmentTransaction.commit();}}
B.3. Get data on Load Fragment (Destination Fragment)
public class testView extends Fragment {
String rdata;
public testView(){
}
public testView(String data){
rdata = data;
}
TextView tvId, tvName;
//traverse variable
public static String MSG = "com.omgrk.OMGRKMngTestAndroid.Test.MSG";
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_test_view, container, false);
// Coding here
tvId = view.findViewById(R.id.tv_test_id);
tvName = view.findViewById(R.id.tv_test_name);
JSONObject jsonObject;
String data = rdata;
try {
jsonObject = new JSONObject(data);
//fill data
tvName.setText(jsonObject.getString("name"));
tvId.setText(jsonObject.getString("id"));
} catch (JSONException e) {
e.printStackTrace();
}
// Coding here
return view;
}
}
Saturday, December 4, 2021
Transfer data one fragment to another two type A. With Bundle, B. With Cunstructor
A.1. Send data from This Fragment (Source Fragment)
public class testList extends Fragment {
//Define Event Listener
private TestFragmentEvent listener;public interface TestFragmentEvent {
public void TestFragmentEvent_Create();
public void TestFragmentEvent_View(String data);}public void onAttach(@NonNull Context context) {
super.onAttach(context);
if (context instanceof SecondFragment.onFrgmtSecondBtnSelected) {
listener = (TestFragmentEvent) context;
} else {
throw new ClassCastException(context.toString() + " must implement listener");
}}
public void f_showData() {String rdata = "{Id:101,Name:"XYZabc"}";
try {
rdata = testDataJsonArray.getJSONObject(i).toString();
} catch (JSONException e) {
e.printStackTrace();
}
listener.TestFragmentEvent_View(rdata);}}
A.2. In Main Activity
public class MainActivity extends AppCompatActivity implements testList.TestFragmentEvent {@Override
public void TestFragmentEvent_View(String data) {
testView testview = new testView();
Bundle bundle = new Bundle();
bundle.putString("rdata", data);
testview.setArguments(bundle);
fragmentManager = getSupportFragmentManager();
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.container_fragment, testview);
fragmentTransaction.commit();}}
A.3. Get data on Load Fragment (Destination Fragment)
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_test_view, container, false);
// Coding here
tvId = view.findViewById(R.id.tv_test_id);
tvName = view.findViewById(R.id.tv_test_name);
String data =this.getArguments().getString(MSG);
Bundle bundle = this.getArguments();
String data = bundle.getString("rdata");
JSONObject jsonObject;
try {
jsonObject = new JSONObject(data);
//fill data
tvName.setText(jsonObject.getString("name"));
tvId.setText(jsonObject.getString("id"));
} catch (JSONException e) {
e.printStackTrace();
}
// Coding here
return view;
}
B.1. Send data from This Fragment (Source Fragment)
public class testList extends Fragment {
//Define Event Listener
private TestFragmentEvent listener;public interface TestFragmentEvent {
public void TestFragmentEvent_Create();
public void TestFragmentEvent_View(String data);}public void onAttach(@NonNull Context context) {
super.onAttach(context);
if (context instanceof SecondFragment.onFrgmtSecondBtnSelected) {
listener = (TestFragmentEvent) context;
} else {
throw new ClassCastException(context.toString() + " must implement listener");
}}
public void f_showData() {String rdata = "{Id:101,Name:"XYZabc"}";
try {
rdata = testDataJsonArray.getJSONObject(i).toString();
} catch (JSONException e) {
e.printStackTrace();
}
listener.TestFragmentEvent_View(rdata);}}
B.2 Main Activity
public class MainActivity extends AppCompatActivity implements testList.TestFragmentEvent {@Override
public void TestFragmentEvent_View(String data) {
testView testview = new testView(data);
fragmentManager = getSupportFragmentManager();
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.container_fragment, testview);
fragmentTransaction.commit();}}
B.3. Get data on Load Fragment (Destination Fragment)
public class testView extends Fragment {
String rdata;
public testView(){
}
public testView(String data){
rdata = data;
}
TextView tvId, tvName;
//traverse variable
public static String MSG = "com.omgrk.OMGRKMngTestAndroid.Test.MSG";
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_test_view, container, false);
// Coding here
tvId = view.findViewById(R.id.tv_test_id);
tvName = view.findViewById(R.id.tv_test_name);
JSONObject jsonObject;
String data = rdata;
try {
jsonObject = new JSONObject(data);
//fill data
tvName.setText(jsonObject.getString("name"));
tvId.setText(jsonObject.getString("id"));
} catch (JSONException e) {
e.printStackTrace();
}
// Coding here
return view;
}
}
Date format in android
public String f_dateFormat (String cdate , String dateToFormat) { // String cdate = "2013-05-15T10:00:00-0700"; ...
-
1. Button in fragment android:drawableLeft="@drawable/ic_baseline_search_24" <Button android :id ="@+id/btn_search...