Support
Quality
Security
License
Reuse
kandi has reviewed FloatingActionButton and discovered the below as its top functions. This is intended to give you an instant insight into FloatingActionButton implemented functionality, and help decide if they suit your requirements.
[DEPRECATED] Android floating action button
Integration
dependencies {
compile 'com.melnykov:floatingactionbutton:1.3.0'
}
License
The MIT License (MIT)
Copyright (c) 2014 Oleksandr Melnykov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Search Filter in RecyclerView not showing anything
public NotesRecyclerAdapter(ArrayList<Note> mNotes, OnNoteListener onNoteListener) {
this.mNotes = mNotes;
this.mOnNoteListener = onNoteListener;
this.notesListAll = new ArrayList<>(); // <---- Empty list
notesListAll.addAll(mNotes); // <--- Fix is here
}
if (note.getContent().toLowerCase().contains(charSequence.toString().toLowerCase())) {
-----------------------
public NotesRecyclerAdapter(ArrayList<Note> mNotes, OnNoteListener onNoteListener) {
this.mNotes = mNotes;
this.mOnNoteListener = onNoteListener;
this.notesListAll = new ArrayList<>(); // <---- Empty list
notesListAll.addAll(mNotes); // <--- Fix is here
}
if (note.getContent().toLowerCase().contains(charSequence.toString().toLowerCase())) {
-----------------------
if (firstInstance) {notesList.clear();}
notesList.addAll(notesListAll);
Assign different actions to a Floating Button on Android
binding.appBarMain.fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment); // change `nav_host_fragment` according to yours
if (navHostFragment != null) {
Fragment currentFragment = navHostFragment.getChildFragmentManager().getFragments().get(0);
if (currentFragment instanceof HomeFragment) {
Toast.makeText(MainActivity.this, "Home Fragment", Toast.LENGTH_SHORT).show();
} else if (currentFragment instanceof SlideshowFragment) {
Toast.makeText(MainActivity.this, "Slideshow Fragment", Toast.LENGTH_SHORT).show();
} else if (currentFragment instanceof GalleryFragment) {
Toast.makeText(MainActivity.this, "Gallery Fragment", Toast.LENGTH_SHORT).show();
}
}
}
});
Negative Margins For RecyclerView Item Decoration
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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="wrap_content"
android:layout_marginBottom="-20dp"
android:background="@android:color/transparent">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/cvTop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="60dp"
android:layout_height="60dp"
android:outlineProvider="none"
app:backgroundTint="@android:color/transparent"
app:layout_anchor="@id/navigation" />
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_gravity="bottom"
android:layout_marginStart="8dp"
android:layout_marginTop="2dp"
android:layout_marginEnd="8dp"
app:backgroundTint="@android:color/holo_blue_dark">
</com.google.android.material.bottomappbar.BottomAppBar>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fabCall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:backgroundTint="@color/fab_green"
app:layout_constraintBottom_toBottomOf="@+id/cvTop"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/cvTop" />
<TextView
android:id="@+id/tv_item_num"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Item No. 0" />
</androidx.constraintlayout.widget.ConstraintLayout>
-----------------------
mRecycler.setChildDrawingOrderCallback(new RecyclerView.ChildDrawingOrderCallback() {
@Override
public int onGetChildDrawingOrder(int childCount, int i) {
return childCount - i - 1;
}
});
class OverlapItemDecoration(context: Context, overlapDp: Int) : RecyclerView.ItemDecoration() {
private val overlapPx: Int
init {
overlapPx = (context.resources.displayMetrics.density * overlapDp.toFloat()).toInt()
}
override fun getItemOffsets(
outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State
) {
if (parent.getChildAdapterPosition(view) == 0) return
outRect.set(0, overlapPx, 0, 0)
}
}
-----------------------
mRecycler.setChildDrawingOrderCallback(new RecyclerView.ChildDrawingOrderCallback() {
@Override
public int onGetChildDrawingOrder(int childCount, int i) {
return childCount - i - 1;
}
});
class OverlapItemDecoration(context: Context, overlapDp: Int) : RecyclerView.ItemDecoration() {
private val overlapPx: Int
init {
overlapPx = (context.resources.displayMetrics.density * overlapDp.toFloat()).toInt()
}
override fun getItemOffsets(
outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State
) {
if (parent.getChildAdapterPosition(view) == 0) return
outRect.set(0, overlapPx, 0, 0)
}
}
EditText wont add data to Spinner
return inflater.inflate(R.layout.fragment_message, container, false);
return view;
-----------------------
return inflater.inflate(R.layout.fragment_message, container, false);
return view;
How to pass variables between 2 different files and manipulate them
class Second extends StatefulWidget {
int counter;
Second(this.counter);
@override
_SecondState createState() => _SecondState();
}
Container(
child: Second(_counter),
),
-----------------------
class Second extends StatefulWidget {
int counter;
Second(this.counter);
@override
_SecondState createState() => _SecondState();
}
Container(
child: Second(_counter),
),
-----------------------
class Second extends StatelessWidget {
final int counter;
const Second({Key key, this.counter}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
color: Colors.red,
width: 200,
height: 300,
child: Text('My increment * 10 : ${counter * 10} '));
}
}
import 'package:flutter/material.dart';
import 'second.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
Container(
child: Second(counter:_counter),
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
class AppStrings {
static Color appColor = Colors.blue;
}
-----------------------
class Second extends StatelessWidget {
final int counter;
const Second({Key key, this.counter}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
color: Colors.red,
width: 200,
height: 300,
child: Text('My increment * 10 : ${counter * 10} '));
}
}
import 'package:flutter/material.dart';
import 'second.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
Container(
child: Second(counter:_counter),
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
class AppStrings {
static Color appColor = Colors.blue;
}
-----------------------
class Second extends StatelessWidget {
final int counter;
const Second({Key key, this.counter}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
color: Colors.red,
width: 200,
height: 300,
child: Text('My increment * 10 : ${counter * 10} '));
}
}
import 'package:flutter/material.dart';
import 'second.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
Container(
child: Second(counter:_counter),
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
class AppStrings {
static Color appColor = Colors.blue;
}
BLoC behaved wrongly when updating the Model
_model.copyWith(
name: name,
ratePerHour: ratePerHour,
isLoading: isLoading,
submitted: submitted,
);
_model = _model.copyWith(
name: name,
ratePerHour: ratePerHour,
isLoading: isLoading,
submitted: submitted,
);
-----------------------
_model.copyWith(
name: name,
ratePerHour: ratePerHour,
isLoading: isLoading,
submitted: submitted,
);
_model = _model.copyWith(
name: name,
ratePerHour: ratePerHour,
isLoading: isLoading,
submitted: submitted,
);
How to view an ArrayList in a horizonal scrollbar?
private ArrayList<TvShowEpisode> mEpisodes = new ArrayList<TvShowEpisode>();
private static final String SHOW_ID = "showId";
mShowId = getActivity().getIntent().getExtras().getString(SHOW_ID);
Cursor cursor = mDatabaseHelper.getEpisodes(mShowId);
try {
while (cursor.moveToNext()) {
mEpisodes.add(new TvShowEpisode(mContext, mShowId,
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE_TITLE)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE_PLOT)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_SEASON)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE_AIRDATE)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE_DIRECTOR)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE_WRITER)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE_GUESTSTARS)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE_RATING)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_HAS_WATCHED)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_FAVOURITE))
));
}
} catch (Exception e) {
} finally {
cursor.close();
}
// populating the listview
mEpisodesList = (ListView) view.findViewById(R.id.episodesList);
ArrayList<String> episodeslist = new ArrayList<String>(mEpisodes.size()); //set initialize capacity as it's know, some negligible performance related reason
for(TvShowEpisode e : mEpisodes){
episodeslist.add(e.mEpisode);
}
// Create The Adapter
ArrayAdapter<String> arrayAdapter =
new ArrayAdapter<String>(mContext,android.R.layout.simple_list_item_1, episodeslist);
// Set The Adapter
mEpisodesList.setAdapter(arrayAdapter);
<HorizontalScrollView
android:id="@+id/hsv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:measureAllChildren="false"
android:scrollbars="none"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<ListView
android:id="@+id/episodesList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp" />
</LinearLayout>
</HorizontalScrollView>
-----------------------
private ArrayList<TvShowEpisode> mEpisodes = new ArrayList<TvShowEpisode>();
private static final String SHOW_ID = "showId";
mShowId = getActivity().getIntent().getExtras().getString(SHOW_ID);
Cursor cursor = mDatabaseHelper.getEpisodes(mShowId);
try {
while (cursor.moveToNext()) {
mEpisodes.add(new TvShowEpisode(mContext, mShowId,
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE_TITLE)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE_PLOT)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_SEASON)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE_AIRDATE)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE_DIRECTOR)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE_WRITER)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE_GUESTSTARS)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE_RATING)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_HAS_WATCHED)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_FAVOURITE))
));
}
} catch (Exception e) {
} finally {
cursor.close();
}
// populating the listview
mEpisodesList = (ListView) view.findViewById(R.id.episodesList);
ArrayList<String> episodeslist = new ArrayList<String>(mEpisodes.size()); //set initialize capacity as it's know, some negligible performance related reason
for(TvShowEpisode e : mEpisodes){
episodeslist.add(e.mEpisode);
}
// Create The Adapter
ArrayAdapter<String> arrayAdapter =
new ArrayAdapter<String>(mContext,android.R.layout.simple_list_item_1, episodeslist);
// Set The Adapter
mEpisodesList.setAdapter(arrayAdapter);
<HorizontalScrollView
android:id="@+id/hsv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:measureAllChildren="false"
android:scrollbars="none"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<ListView
android:id="@+id/episodesList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp" />
</LinearLayout>
</HorizontalScrollView>
-----------------------
private ArrayList<TvShowEpisode> mEpisodes = new ArrayList<TvShowEpisode>();
private static final String SHOW_ID = "showId";
mShowId = getActivity().getIntent().getExtras().getString(SHOW_ID);
Cursor cursor = mDatabaseHelper.getEpisodes(mShowId);
try {
while (cursor.moveToNext()) {
mEpisodes.add(new TvShowEpisode(mContext, mShowId,
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE_TITLE)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE_PLOT)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_SEASON)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE_AIRDATE)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE_DIRECTOR)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE_WRITER)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE_GUESTSTARS)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE_RATING)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_HAS_WATCHED)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_FAVOURITE))
));
}
} catch (Exception e) {
} finally {
cursor.close();
}
// populating the listview
mEpisodesList = (ListView) view.findViewById(R.id.episodesList);
ArrayList<String> episodeslist = new ArrayList<String>(mEpisodes.size()); //set initialize capacity as it's know, some negligible performance related reason
for(TvShowEpisode e : mEpisodes){
episodeslist.add(e.mEpisode);
}
// Create The Adapter
ArrayAdapter<String> arrayAdapter =
new ArrayAdapter<String>(mContext,android.R.layout.simple_list_item_1, episodeslist);
// Set The Adapter
mEpisodesList.setAdapter(arrayAdapter);
<HorizontalScrollView
android:id="@+id/hsv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:measureAllChildren="false"
android:scrollbars="none"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<ListView
android:id="@+id/episodesList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp" />
</LinearLayout>
</HorizontalScrollView>
-----------------------
private ArrayList<TvShowEpisode> mEpisodes = new ArrayList<TvShowEpisode>();
private static final String SHOW_ID = "showId";
mShowId = getActivity().getIntent().getExtras().getString(SHOW_ID);
Cursor cursor = mDatabaseHelper.getEpisodes(mShowId);
try {
while (cursor.moveToNext()) {
mEpisodes.add(new TvShowEpisode(mContext, mShowId,
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE_TITLE)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE_PLOT)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_SEASON)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE_AIRDATE)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE_DIRECTOR)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE_WRITER)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE_GUESTSTARS)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_EPISODE_RATING)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_HAS_WATCHED)),
cursor.getString(cursor.getColumnIndex(DbAdapterTvShowEpisodes.KEY_FAVOURITE))
));
}
} catch (Exception e) {
} finally {
cursor.close();
}
// populating the listview
mEpisodesList = (ListView) view.findViewById(R.id.episodesList);
ArrayList<String> episodeslist = new ArrayList<String>(mEpisodes.size()); //set initialize capacity as it's know, some negligible performance related reason
for(TvShowEpisode e : mEpisodes){
episodeslist.add(e.mEpisode);
}
// Create The Adapter
ArrayAdapter<String> arrayAdapter =
new ArrayAdapter<String>(mContext,android.R.layout.simple_list_item_1, episodeslist);
// Set The Adapter
mEpisodesList.setAdapter(arrayAdapter);
<HorizontalScrollView
android:id="@+id/hsv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:measureAllChildren="false"
android:scrollbars="none"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<ListView
android:id="@+id/episodesList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp" />
</LinearLayout>
</HorizontalScrollView>
How to display and hide progress bar from fragment in Android?
private void displayProgressBar(boolean visible) {
RelativeLayout layout = new RelativeLayout(getContext());
ProgressBar progressBar = new ProgressBar(MainActivity.getActivity(),null,android.R.attr.progressBarStyleLarge);
progressBar.setIndeterminate(true);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(100,100);
params.addRule(RelativeLayout.CENTER_IN_PARENT);
if (visible) {
layout.addView(progressBar, params);
MainActivity.getActivity().setContentView(layout);
progressBar.setVisibility(View.VISIBLE);
} else {
progressBar.setVisibility(View.INVISIBLE);
}
}
ProgressBar progressBar;
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="24dp"
android:visibility="visible" />
progressBar.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.GONE);
-----------------------
private void displayProgressBar(boolean visible) {
RelativeLayout layout = new RelativeLayout(getContext());
ProgressBar progressBar = new ProgressBar(MainActivity.getActivity(),null,android.R.attr.progressBarStyleLarge);
progressBar.setIndeterminate(true);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(100,100);
params.addRule(RelativeLayout.CENTER_IN_PARENT);
if (visible) {
layout.addView(progressBar, params);
MainActivity.getActivity().setContentView(layout);
progressBar.setVisibility(View.VISIBLE);
} else {
progressBar.setVisibility(View.INVISIBLE);
}
}
ProgressBar progressBar;
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="24dp"
android:visibility="visible" />
progressBar.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.GONE);
-----------------------
private void displayProgressBar(boolean visible) {
RelativeLayout layout = new RelativeLayout(getContext());
ProgressBar progressBar = new ProgressBar(MainActivity.getActivity(),null,android.R.attr.progressBarStyleLarge);
progressBar.setIndeterminate(true);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(100,100);
params.addRule(RelativeLayout.CENTER_IN_PARENT);
if (visible) {
layout.addView(progressBar, params);
MainActivity.getActivity().setContentView(layout);
progressBar.setVisibility(View.VISIBLE);
} else {
progressBar.setVisibility(View.INVISIBLE);
}
}
ProgressBar progressBar;
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="24dp"
android:visibility="visible" />
progressBar.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.GONE);
-----------------------
private void displayProgressBar(boolean visible) {
RelativeLayout layout = new RelativeLayout(getContext());
ProgressBar progressBar = new ProgressBar(MainActivity.getActivity(),null,android.R.attr.progressBarStyleLarge);
progressBar.setIndeterminate(true);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(100,100);
params.addRule(RelativeLayout.CENTER_IN_PARENT);
if (visible) {
layout.addView(progressBar, params);
MainActivity.getActivity().setContentView(layout);
progressBar.setVisibility(View.VISIBLE);
} else {
progressBar.setVisibility(View.INVISIBLE);
}
}
ProgressBar progressBar;
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="24dp"
android:visibility="visible" />
progressBar.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.GONE);
-----------------------
private void displayProgressBar(boolean visible) {
RelativeLayout layout = view.findViewById(R.id.note);
if (visible) {
progressBar = new ProgressBar(MainActivity.getActivity(),null,android.R.attr.progressBarStyleLarge);
progressBar.setIndeterminate(true);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(100,100);
params.addRule(RelativeLayout.CENTER_IN_PARENT);
layout.addView(progressBar, params);
progressBar.setVisibility(View.VISIBLE);
} else {
layout.removeView(progressBar);
progressBar.setVisibility(View.GONE);
}
}
What is "dirty" in Flutter & what is causing this "dirty" state?
GetBuilder<SimpleMath>(
builder: (simpleMath) => Text('Variable summation: ' +
simpleMath
.summationVariables(shouldUpdate: false)
.toString())),
GetBuilder<SimpleMath>(
builder: (simpleMath) => Text(simpleMath
.summationReturns(shouldUpdate: false)
.toString())),
int summationVariables({bool shouldUpdate = true}) {
int sum = controller.count + observable.count.value;
if (shouldUpdate) update();
return sum;
}
int summationReturns({bool shouldUpdate = true}) {
int sum = controller.returnCount() + observable.returnCount();
print('Summation of return values: ' + sum.toString());
if (shouldUpdate) update();
return sum;
}
-----------------------
GetBuilder<SimpleMath>(
builder: (simpleMath) => Text('Variable summation: ' +
simpleMath
.summationVariables(shouldUpdate: false)
.toString())),
GetBuilder<SimpleMath>(
builder: (simpleMath) => Text(simpleMath
.summationReturns(shouldUpdate: false)
.toString())),
int summationVariables({bool shouldUpdate = true}) {
int sum = controller.count + observable.count.value;
if (shouldUpdate) update();
return sum;
}
int summationReturns({bool shouldUpdate = true}) {
int sum = controller.returnCount() + observable.returnCount();
print('Summation of return values: ' + sum.toString());
if (shouldUpdate) update();
return sum;
}
How get Notification automatically flutter
const _time = const Duration(minutes:5) ;
new Timer.periodic(_time, (Timer t) => print('flutter'));
QUESTION
Search Filter in RecyclerView not showing anything
Asked 2021-Jun-15 at 21:08My app consists in letting you add lists in which you can keep your notes. Therefore, I have this NotesListActivity where I can add and keep my Lists. I wanted to filter this lists following the https://www.youtube.com/watch?v=CTvzoVtKoJ8 tutorial and then I tried to adapt it to my code like below. Could you please tell me what is the problem here, cause I don't even get an error, I just not get any title of list as result. So, this is what I have in my RecyclerAdapter:
public class NotesRecyclerAdapter extends RecyclerView.Adapter<NotesRecyclerAdapter.ViewHolder> implements Filterable {
private static final String TAG = "NotesRecyclerAdapter";
ArrayList<Note> notesListAll;
private ArrayList<Note> mNotes;
private OnNoteListener mOnNoteListener;
public NotesRecyclerAdapter(ArrayList<Note> mNotes, OnNoteListener onNoteListener) {
this.mNotes = mNotes;
this.mOnNoteListener = onNoteListener;
this.notesListAll = new ArrayList<>();
notesListAll.addAll(mNotes);
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
...
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
...
}
@Override
public int getItemCount() {
return mNotes.size();
}
@Override
public Filter getFilter() { return myFilter; }
Filter myFilter = new Filter() {
//runs on background thread
@Override
protected FilterResults performFiltering(CharSequence charSequence) {
List<Note> filteredList = new ArrayList<>();
if (charSequence == null || charSequence.length() == 0) {
filteredList.addAll(notesListAll);
} else {
for (Note note : notesListAll) {
if (note.getTitle().toLowerCase().contains(charSequence.toString().toLowerCase())) {
filteredList.add(note);
}
}
}
FilterResults filterResults = new FilterResults();
filterResults.values = filteredList;
return filterResults;
}
//runs on a ui thread
@Override
protected void publishResults(CharSequence charSequence, FilterResults filterResults) {
mNotes.clear();
mNotes.addAll((Collection <? extends Note>) filterResults.values );
notifyDataSetChanged();
}
};
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
...
}
@Override
public void onClick(View view) {
...
}
}
public interface OnNoteListener{
void onNoteClick(int position);
}
}
And this in my Activity:
public class NotesListActivity extends AppCompatActivity implements
NotesRecyclerAdapter.OnNoteListener,
FloatingActionButton.OnClickListener
{
private static final String TAG = "NotesListActivity";
private RecyclerView mRecyclerView;
private ArrayList<Note> mNotes = new ArrayList<>();
private NotesRecyclerAdapter mNoteRecyclerAdapter;
private NoteRepository mNoteRepository;
@Override
protected void onCreate(Bundle savedInstanceState) {
...
initRecyclerView();
mNoteRepository = new NoteRepository(this);
retrieveNotes();
setSupportActionBar((Toolbar)findViewById(R.id.notes_toolbar));
setTitle("Notes");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.search,menu);
MenuItem item = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) item.getActionView();
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
// NotesRecyclerAdapter.getFilter().filter(newText);
mNoteRecyclerAdapter.getFilter().filter(newText);
return false;
}
});
return super.onCreateOptionsMenu(menu);
}
private void retrieveNotes() {
mNoteRepository.retrieveNotesTask().observe(this, new Observer<List<Note>>() {
@Override
public void onChanged(@Nullable List<Note> notes) {
...
}
});
}
private void initRecyclerView(){
...
}
@Override
public void onNoteClick(int position) {
...
}
@Override
public void onClick(View view) {
...
}
private void deleteNote(Note note) {
...
}
ItemTouchHelper.SimpleCallback itemTouchHelperCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.RIGHT) {
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
deleteNote(mNotes.get(viewHolder.getAdapterPosition()));
}
};
}
ANSWER
Answered 2021-Jun-13 at 20:18The problem is that you are using an empty notesListAll
list for filtering results; you need to populate it with the list of notes in the constructor
public NotesRecyclerAdapter(ArrayList<Note> mNotes, OnNoteListener onNoteListener) {
this.mNotes = mNotes;
this.mOnNoteListener = onNoteListener;
this.notesListAll = new ArrayList<>(); // <---- Empty list
notesListAll.addAll(mNotes); // <--- Fix is here
}
Also, you're filtering based on getContent()
, probably the searched text is not a part of that content, so you need to filter out some other results within the Note
data class.
if (note.getContent().toLowerCase().contains(charSequence.toString().toLowerCase())) {
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Explore Related Topics
Save this library and start creating your kit