Support
Quality
Security
License
Reuse
kandi has reviewed Android and discovered the below as its top functions. This is intended to give you an instant insight into Android implemented functionality, and help decide if they suit your requirements.
Android related examples
Disable overglow effect in ViewPager2
//disable glow effect when over-scroll
if (viewPager2.getChildAt(0) instanceof RecyclerView) {
viewPager2.getChildAt(0).setOverScrollMode(View.OVER_SCROLL_NEVER);
}
collapsingtoolbarlayout recyclerview working separately
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:id="@+id/itineraryListFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:windowBackground">
<androidx.coordinatorlayout.widget.CoordinatorLayout 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:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways">
<Button
android:id="@+id/button_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_start_margin"
android:layout_marginTop="@dimen/_20sdp"
android:layout_marginEnd="@dimen/activity_end_margin"
android:background="@null"
android:clickable="true"
android:drawableStart="@drawable/ic_arrow_booking_details"
android:gravity="start|center_vertical" />
<ImageView
android:id="@+id/iv_background_image"
android:layout_width="match_parent"
android:layout_height="@dimen/_123sdp"
android:contentDescription="@string/name_app"
android:scaleType="centerCrop"
app:srcCompat="@drawable/booking_details_background" />
<ImageView
android:id="@+id/iv_background_rectangle"
android:layout_width="match_parent"
android:layout_height="@dimen/_123sdp"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
app:srcCompat="@drawable/rectangle_booking_details" />
<TextView
android:id="@+id/tv_background_title"
style="@style/font_title_bookingdetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_start_margin"
android:layout_marginTop="95dp"
android:layout_marginEnd="@dimen/activity_end_margin"
android:gravity="start|center_vertical"
android:text="@string/text_trek_everest_name"
android:textColor="@color/colorPrimary" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="26dp" />
<androidx.appcompat.widget.Toolbar
android:layout_width="?attr/actionBarSize"
android:layout_height="wrap_content"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/tv_title_itinerary_list"
style="@style/font_title_day1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_start_margin"
android:layout_marginTop="@dimen/_15sdp"
android:layout_marginBottom="@dimen/activity_end_margin"
android:gravity="center_vertical"
android:text="@string/dashboard_itinerary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.235" />
<include layout="@layout/booking_itinerary_recyclerview" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</FrameLayout>
Import compose sample projects to android studio version 4.2
Android Studio 4.2
Build #AI-202.7660.26.42.7322048, built on April 29, 2021
Android Studio Arctic Fox | 2020.3.1 Beta 03
-----------------------
Android Studio 4.2
Build #AI-202.7660.26.42.7322048, built on April 29, 2021
Android Studio Arctic Fox | 2020.3.1 Beta 03
error: cannot find symbol | class ApplicationComponent
@dagger.hilt.InstallIn(value = {ApplicationComponent.class})
^
symbol: class ApplicationComponenterror: [Hilt]
@InstallIn, 'value' class is invalid or missing: @dagger.hilt.InstallIn({<error>})
[Hilt] Processing did not complete. See error above for details.
How can add a Row dynamically in flutter?
return Container(
padding: EdgeInsets.all(16.0),
width: 100.0.w,
child: Center(
child: Wrap(
spacing: 10.0,
runSpacing: 10.0,
direction: Axis.horizontal,
crossAxisAlignment: WrapCrossAlignment.center,
children:iconos, //LIST OF ITEMS
),
),
);
Android Studio Flutter - WARNING: Another emulator is still running - windows 10
/F Specifies that processes be forcefully ended. This parameter is ignored for remote processes; all remote processes are forcefully ended.
/T Ends the specified process and any child processes started by it.
/IM Specifies the image name of the process to be terminated.
How to make mobile Safari show a background gif properly
.loader {
position: fixed;
left: 50%;
top: 50%;
border-radius: 50%;
width: 128px;
height: 128px;
margin: -76px 0 0 -76px;
border: 16px solid #f3f3f3;
border-top: 16px solid #fff;
-webkit-animation: spin 5s linear infinite;
animation: spin 5s linear infinite;
}
/* Safari */
@-webkit-keyframes spin {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
</style>
</head>
<body>
<div class="loader"><img src="https://www.w3schools.com/html/programming.gif" alt="Computer man" style="width:48px;height:48px;"></div>
</body>
</html>
-----------------------
.loader {
position: fixed;
left: 50%;
top: 50%;
border-radius: 50%;
width: 128px;
height: 128px;
margin: -76px 0 0 -76px;
border: 16px solid #f3f3f3;
border-top: 16px solid #fff;
-webkit-animation: spin 5s linear infinite;
animation: spin 5s linear infinite;
}
/* Safari */
@-webkit-keyframes spin {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
</style>
</head>
<body>
<div class="loader"><img src="https://www.w3schools.com/html/programming.gif" alt="Computer man" style="width:48px;height:48px;"></div>
</body>
</html>
Dynamically creating button row column wise
private void createLayoutDynamically(int n) {
int count=0;
LinearLayout layout = (LinearLayout) findViewById(R.id.myDynamicLayout); //Main Vertical Linear Layout
layout.setOrientation(LinearLayout.VERTICAL); //Setting that LinearLayout as Vertical
for (int i = 0; i < n; i++)
{
LinearLayout row=new LinearLayout(this); //new Horizontal LinearLayout
row.setOrientation(LinearLayout.HORIZONTAL); //keeping this layout's orientation horizontal
row.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); //setting it's width and Height
for(int j=0;j<n;j++)
{
Button myButton = new Button(this);
myButton.setLayoutParams(new LayoutParams(50, LayoutParams.WRAP_CONTENT));
myButton.setText("");
myButton.setId(count);
final int id_ = myButton.getId();
row.addView(myButton);
count++;
}
//Once Button Added to Horizontal Row add it back to Vertical Linearlayout
layout.addView(row);
}
}
Extract string values from a string using regex in java
^([a-zA-Z0-9]+)\s+Confirmed\.on\h+(\d{1,2}/\d{1,2}/\d\d)\h+at\h+(\d{1,2}:\d{1,2})\w*Ksh(\d+(?:\.\d+)?).*?\bfrom\h+(\d+)\h+([^.]+)\.
final String regex = "^([a-zA-Z0-9]+)\\s+Confirmed\\.on\\h+(\\d{1,2}/\\d{1,2}/\\d\\d)\\h+at\\h+(\\d{1,2}:\\d{1,2})\\w*Ksh(\\d+(?:\\.\\d+)?).*?\\bfrom\\h+(\\d+)\\h+([^.]+)\\.";
final String string2 = "PFEDDTYG0D Confirmed.on 14/6/21 at 12:46PMKsh260.00 received from 254725400049 JOHN DOE. New Account balance is Ksh1,666. Transaction cost, Ksh1";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string2);
if(matcher.find()) {
String code = matcher.group(1);
String amountReceived = matcher.group(4);
String tel = matcher.group(5);
String from = matcher.group(6);
String date = matcher.group(2);
String time = matcher.group(3);
String format = "code: %s amount received: %s from: %s date: %s time: %s tel: %s";
System.out.println(String.format(format, code, amountReceived, from, date, time, tel));
}
code: PFEDDTYG0D amount received: 260.00 from: JOHN DOE date: 14/6/21 time: 12:46 tel: 254725400049
-----------------------
^([a-zA-Z0-9]+)\s+Confirmed\.on\h+(\d{1,2}/\d{1,2}/\d\d)\h+at\h+(\d{1,2}:\d{1,2})\w*Ksh(\d+(?:\.\d+)?).*?\bfrom\h+(\d+)\h+([^.]+)\.
final String regex = "^([a-zA-Z0-9]+)\\s+Confirmed\\.on\\h+(\\d{1,2}/\\d{1,2}/\\d\\d)\\h+at\\h+(\\d{1,2}:\\d{1,2})\\w*Ksh(\\d+(?:\\.\\d+)?).*?\\bfrom\\h+(\\d+)\\h+([^.]+)\\.";
final String string2 = "PFEDDTYG0D Confirmed.on 14/6/21 at 12:46PMKsh260.00 received from 254725400049 JOHN DOE. New Account balance is Ksh1,666. Transaction cost, Ksh1";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string2);
if(matcher.find()) {
String code = matcher.group(1);
String amountReceived = matcher.group(4);
String tel = matcher.group(5);
String from = matcher.group(6);
String date = matcher.group(2);
String time = matcher.group(3);
String format = "code: %s amount received: %s from: %s date: %s time: %s tel: %s";
System.out.println(String.format(format, code, amountReceived, from, date, time, tel));
}
code: PFEDDTYG0D amount received: 260.00 from: JOHN DOE date: 14/6/21 time: 12:46 tel: 254725400049
-----------------------
^([a-zA-Z0-9]+)\s+Confirmed\.on\h+(\d{1,2}/\d{1,2}/\d\d)\h+at\h+(\d{1,2}:\d{1,2})\w*Ksh(\d+(?:\.\d+)?).*?\bfrom\h+(\d+)\h+([^.]+)\.
final String regex = "^([a-zA-Z0-9]+)\\s+Confirmed\\.on\\h+(\\d{1,2}/\\d{1,2}/\\d\\d)\\h+at\\h+(\\d{1,2}:\\d{1,2})\\w*Ksh(\\d+(?:\\.\\d+)?).*?\\bfrom\\h+(\\d+)\\h+([^.]+)\\.";
final String string2 = "PFEDDTYG0D Confirmed.on 14/6/21 at 12:46PMKsh260.00 received from 254725400049 JOHN DOE. New Account balance is Ksh1,666. Transaction cost, Ksh1";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string2);
if(matcher.find()) {
String code = matcher.group(1);
String amountReceived = matcher.group(4);
String tel = matcher.group(5);
String from = matcher.group(6);
String date = matcher.group(2);
String time = matcher.group(3);
String format = "code: %s amount received: %s from: %s date: %s time: %s tel: %s";
System.out.println(String.format(format, code, amountReceived, from, date, time, tel));
}
code: PFEDDTYG0D amount received: 260.00 from: JOHN DOE date: 14/6/21 time: 12:46 tel: 254725400049
Dropdown in custom Alertdialog doesn't show any items (Kotlin)
// inflate your layout
val dialogView = LayoutInflater.from(this).inflate(R.layout.pizza_alert_dialog, null, false)
// and set it as dialog view
pizzaDialogBuilder.setView(dialogView)
// then call findViewById on this ViewGroup to get the Spinner
val pizzaDropdown = dialogView.findViewById<Spinner>(R.id.pizzaSelection)
QUESTION
There was a problem saving the text in EditText to a file
Asked 2021-Jun-16 at 01:47This code receives information from an acquaintance you want to register in editText, and then clicks finButton to save the information you receive as a file called friendlist.txt. However, the Toast message is outputted from the try-catch statement that is currently performed when finButton is pressed. Also, the checkpermission does not work, which is wrapped in a try~catch statement, but does not have output on the logcat.
And manifest.
uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
is written.
Please let me know the solution. And this content is written with a translator, so the sentence can be strange.
when you press finButton, the logcat is shown below.
The code corresponding to the 116th line is this.
FileOutputStream outstream = openFileOutput("friendList.txt", Activity.MODE_WORLD_WRITEABLE);
public class EnteringInformationOfFriendActivity extends AppCompatActivity {
Button finButton;
EditText phoneNumberEditText, nameEditText, emailEditText, groupEditText, memoEditText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_entering_information_of_friend);
phoneNumberEditText = (EditText) findViewById(R.id.phoneNumberEditText);
nameEditText = (EditText) findViewById(R.id.nameEditText);
emailEditText = (EditText) findViewById(R.id.emailEditText);
groupEditText = (EditText) findViewById(R.id.groupEditText);
memoEditText = (EditText) findViewById(R.id.memoEditText);
try{
checkPermission();
}
catch (Exception e){
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
String exceptionAsStrting = sw.toString();
Log.e("CSP", exceptionAsStrting);
e.printStackTrace();
}
finButton = (Button) findViewById(R.id.finButton);
finButton.setOnClickListener(v -> {
try{
String phoneTxt = phoneNumberEditText.getText().toString().trim();
String nameTxt = nameEditText.getText().toString().trim();
String emailTxt = emailEditText.getText().toString().trim();
String groupTxt = groupEditText.getText().toString().trim();
String memoTxt = memoEditText.getText().toString().trim();
String friendInfoTxt = phoneTxt + "-" + nameTxt + "-" + emailTxt + "-" + groupTxt + "-" + memoTxt;
FileOutputStream outstream = openFileOutput("friendList.txt", Activity.MODE_WORLD_WRITEABLE);
outstream.write(friendInfoTxt.getBytes());
outstream.close();
Intent intent = new Intent(v.getContext(), FriendListActivity.class);
startActivity(intent);
} catch (Exception e){
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
String exceptionAsStrting = sw.toString();
Log.e("Filesave", exceptionAsStrting);
e.printStackTrace();
Toast.makeText(this.getApplicationContext(), "Save failed.", Toast.LENGTH_SHORT).show();
}
});
}
public void checkPermission(){
if(checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
}
}
}
ANSWER
Answered 2021-Jun-16 at 01:47Try with Context.MODE_APPEND or Context.MODE_PRIVATE instead of Activity.MODE_WORLD_WRITEABLE
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Save this library and start creating your kit
Save this library and start creating your kit