logo
down
shadow

How to create a closed (circular) ListView?


How to create a closed (circular) ListView?

By : Krtl
Date : October 23 2020, 03:00 PM
Does that help My colleague Joe, and I believe we have found a simpler way to solve the same problem. In our solution though instead of extending BaseAdapter we extend ArrayAdapter.
The code is as follows :
code :


Share : facebook icon twitter icon
How to create a circular ListView?

How to create a circular ListView?


By : ahmet rasit
Date : March 29 2020, 07:55 AM
To fix this issue I think Android SDK: Creating a Rotating Dialer will help you to create your layout.
You have to modify code yourself to achieve your goal. May be this is a good start for you. :)
Closed or circular Horizontal ListView Android

Closed or circular Horizontal ListView Android


By : Kasper Gantzhorn
Date : March 29 2020, 07:55 AM
will help you As per your requirement you want circular/infinite scrolling horizontal list view,
This is InfiniteScrollView which may help.You need to update this library as per your requirement and change ImageView to any other view which you want to scroll horizontally.
Closed or circular Vertical ListView Android

Closed or circular Vertical ListView Android


By : user2065854
Date : March 29 2020, 07:55 AM
hope this fix your issue I have an Vertical listview i want listview should be closed. For example if the last item is reached in Listview then show the first item below the last item. It means item should be in circular format. And if i scroll from first item it should show last item before first item. I want scrolling for both side.
code :
public class MainActivity extends Activity {
ListView list;
long startTime;
long endTime;


List<String> mList = new ArrayList<String>();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    list = (ListView) findViewById(R.id.list);
    downloadDetails();

     String str;
     for (int i = 0; i < 10; i++) {
     str = new String("Data --- " + i);
     mList.add(str);
     }
     CircularAdapter adapter = new CircularAdapter(this, 0, mList);
        list.setAdapter(adapter);
    final YourRunnable runy = new YourRunnable();

    list.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {

                startTime = (new Date()).getTime();
                runy.onPause();// pausing thread actually pauses scrolling
            }
            if (event.getAction() == MotionEvent.ACTION_UP) {
                endTime = (new Date()).getTime();
                if ((endTime - startTime) <= 100) {// 100 mill second limit
                                                    // for click

                    // Log.i("ITEM CLICK() ", "item : ");
                }

                runy.onResume(); // resume scrolling
            }

            return false;
        }

    });

    new Thread(runy).start();

}





class YourRunnable implements Runnable {
    private Object mPauseLock;
    private boolean mPaused;
    private boolean mFinished;

    public YourRunnable() {
        mPauseLock = new Object();
        mPaused = false;
        mFinished = false;
    }

    @SuppressLint("NewApi")
    public void run() {
        while (!mFinished) {
            // for loop is not infinite but enough as Integer.MAX_VALUE
            for (int index = 0; index < list.getAdapter().getCount(); index++) {
                list.smoothScrollToPositionFromTop(list.getLastVisiblePosition() + 1, 0, 10000);
                try {
                    // it helps scrolling to stay smooth as possible (by
                    // experiment)
                    Thread.sleep(3000);
                    synchronized (mPauseLock) {
                        while (mPaused) {
                            try {
                                mPauseLock.wait();// putting thread in wait
                                                    // list of mPauseLock
                                                    // object
                            } catch (InterruptedException e) {
                            }
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }

        }
    }

    // to pause list
    public void onPause() {
        synchronized (mPauseLock) {
            mPaused = true;
        }
    }

    // resume thread
    public void onResume() {
        synchronized (mPauseLock) {
            mPaused = false;
            mPauseLock.notifyAll();// notify all object that are waiting on
                                    // the wait list of mPauseLock object
        }
    }

}

private class CircularAdapter extends ArrayAdapter {

    List<String> mlist;
    Context mContext;
    LayoutInflater inflater;
    public final int HALF_MAX_VALUE = Integer.MAX_VALUE / 2;
    public final int MIDDLE;

    @SuppressWarnings("unchecked")
    public CircularAdapter(Context ctx, int resId, List<String> objects) {
        super(ctx, resId, objects);
        mContext = ctx;
        mlist = objects;
        inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        MIDDLE = HALF_MAX_VALUE - HALF_MAX_VALUE % mlist.size();

    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return Integer.MAX_VALUE;
    }

    @Override
    public String getItem(int position) {
        // TODO Auto-generated method stub
        int relativePos = position % mlist.size();
        Log.i("RELATIVE : ", " POS:" + relativePos);
        return mlist.get(relativePos);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;

        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item, parent, false);
            holder.name = (TextView) convertView.findViewById(R.id.name);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        String model = getItem(position);
        holder.name.setText(model);

        convertView.setOnClickListener(new ListenerT(model) {

            @Override
            public void onClick(View v) {
                Log.i("CLICK", "ITEM---" + name);

            }
        });

        return convertView;

    }

}

// use your own listener to pass parameter
private class ListenerT implements OnClickListener {

    String name;

    public ListenerT(String nm) {
        name = nm;
    }

    @Override
    public void onClick(View v) {

    }

}

private class ViewHolder {
    TextView name;
}
how to create closed circular Recyclerview with custom Recycler adapter?

how to create closed circular Recyclerview with custom Recycler adapter?


By : Bharath
Date : March 29 2020, 07:55 AM
I wish this help you I looked in a little deep and found a working solution/hack here.I have tested it and it works well.I am closing this question. thanks!
How to create circular ListView in Flutter

How to create circular ListView in Flutter


By : yatharth97
Date : March 29 2020, 07:55 AM
I hope this helps you . Circular List View Demo. Which Is helpful for You May be.
Main.dart
code :
import 'package:master/numbers_list.dart';
import 'package:master/radial_list.dart';
import 'package:meta/meta.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(MyHomePage());
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: new ThemeData(
        accentColor: Colors.blue,
      ),
      home: HomePage(),
    );
  }
}



class HomePage extends StatefulWidget {

  RadialListViewModel radialList;

  HomePage({
    @required this.radialList
  });

  @override
  HomePageState createState() {
    return new HomePageState();
  }
}

class HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: new AppBar(
        title: Text("My Home Page"),
      ),
      body: Stack(
        children: <Widget>[
          RadialList(
            radialList: radialNumbers,
            radius: 150.00,
          ),

        ],
      )
    );
  }
}
import 'package:master/radial_list.dart';

final RadialListViewModel radialNumbers = new RadialListViewModel(
  items: [
    new RadialListItemViewModel(
      number: 1,
      isSelected: true,
    ),
    new RadialListItemViewModel(
      number: 2,
      isSelected: false,
    ),
    new RadialListItemViewModel(
      number: 3,
      isSelected: false,
    ),new RadialListItemViewModel(
      number: 4,
      isSelected: false,
    ),
    new RadialListItemViewModel(
      number: 5,
      isSelected: false,
    ),
    new RadialListItemViewModel(
      number: 6,
      isSelected: false,
    ),
    new RadialListItemViewModel(
      number: 7,
      isSelected: false,
    ),
    new RadialListItemViewModel(
      number: 8,
      isSelected: false,
    ),
    new RadialListItemViewModel(
      number: 9,
      isSelected: false,
    ),
    new RadialListItemViewModel(
      number: 10,
      isSelected: false,
    ),
    new RadialListItemViewModel(
      number: 11,
      isSelected: false,
    ),new RadialListItemViewModel(
      number: 12,
      isSelected: false,
    ),
  ]
);
import 'package:flutter/material.dart';
import 'dart:math';
import 'package:master/radial_position.dart';

class RadialList extends StatefulWidget {

  final RadialListViewModel radialList;
  final double radius;

  RadialList({
    this.radialList,
    this.radius,

  });

  List<Widget> _radialListItems(){

    final double firstItemAngle = pi;
    final double lastItemAngle = pi;
    final double angleDiff = (firstItemAngle + lastItemAngle) / (radialList.items.length);

    double currentAngle = firstItemAngle;
    return radialList.items.map((RadialListItemViewModel viewModel){
      final listItem = _radialListItem(viewModel,currentAngle);
      currentAngle += angleDiff;
      return listItem;
    }).toList();
  }

  Widget _radialListItem(RadialListItemViewModel viewModel, double angle){
      return Transform(
        transform: new Matrix4.translationValues(
          180.0,
          250.0,
          0.0
        ),
        child: RadialPosition(
          radius: radius,
          angle: angle,
          child: new RadialListItem(
            listItem: viewModel,
          ),
        ),
      );
  }

  @override
  RadialListState createState() {
    return new RadialListState();
  }
}

class RadialListState extends State<RadialList> {
  @override
  Widget build(BuildContext context) {
    return new Stack(
      children: widget._radialListItems(),
    );
  }
}

class RadialListItem extends StatefulWidget {

  final RadialListItemViewModel listItem;

  RadialListItem({
    this.listItem
  });

  @override
  RadialListItemState createState() {
    return new RadialListItemState();
  }

}

class RadialListItemState extends State<RadialListItem> {
  @override
  Widget build(BuildContext context) {
    return Transform(
      transform: new Matrix4.translationValues(-30.0, -30.0, 0.0),
      child: Container(
        width: 60.0,
        height: 60.0,
        decoration: new BoxDecoration(
          shape: BoxShape.circle,
          color: Colors.deepPurpleAccent,
          border: new Border.all(
            color: Colors.red,
            width: 2.0
          )
        ),
        child: Padding(
          padding: const EdgeInsets.all(0.0),
          child: OutlineButton(
            shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(60.0)),
            color: Colors.transparent,
            onPressed: () {
              setState(() {
                widget.listItem.isSelected = true;
                //widget.listItem.number = widget.listItem.number + 1;
              });
            },
            child: new Text(
                widget.listItem.number.toString(),
                style: new TextStyle(
                color: widget.listItem.isSelected ? Colors.red : Colors.yellow,
                fontSize: 20.0
              ),
            ),
          ),
        ),
      ),
    );
  }
}

class RadialListViewModel{
  final List<RadialListItemViewModel> items;

  RadialListViewModel({
    this.items = const [],
  });

}


class RadialListItemViewModel{
  int number;
  bool isSelected;

  RadialListItemViewModel({
    this.isSelected=false,
    this.number,
  });

}
   import 'package:flutter/material.dart';
import 'dart:math';


class RadialPosition extends StatefulWidget {

  final double radius;
  final double angle;
  final Widget child;

  RadialPosition({
    this.angle,
    this.child,
    this.radius,
  });


  @override
  RadialPositionState createState() {
    return new RadialPositionState();
  }
}

class RadialPositionState extends State<RadialPosition> {
  @override
  Widget build(BuildContext context) {
    final x = cos(widget.angle)  * widget.radius;
    final y = sin(widget.angle) * widget.radius;

    return Transform(
      transform: new Matrix4.translationValues(x, y, 0.0),
      child: widget.child,
    );
  }
}
Related Posts Related Posts :
  • Getting a string value from the strings.xml resource file and set it in an interface class
  • Flutter, sign with both debug keys and release keys on Android
  • will an android service run code from the Xamarin Forms Project even when the app is closed?
  • Change boolean values on listviewitems in firebase
  • Android Studio 3.2.1: mixing versions can lead to runtime crashes when connect firebase
  • FCM migration without losing the old token
  • Change reported Version Number in Fabric Crashlytics
  • lateinit property mMap has not been initialized
  • Android - PWA does not open in standalone mode with service worker
  • Does LeakCanary has callback?
  • How to disable back button after splash screen in React Native
  • Assets Folder Not Including HTML Files In NativeScript Android Build
  • Dagger: What if I *WANT* a new instance every time?
  • How to get mailto working on android chrome?
  • SSO web login in android app with customtabs
  • how to make specific button side curved
  • remove item onlongclick from listview
  • header image alignment coming wrongly in NavigationView android
  • How to add many spaces after the text in TextView
  • how to set "Back Button" , closing activies except main activity in android?
  • Unable to run emulator on Android Studio || Windows 10
  • How can I achieve this requirement using Rx Java
  • How to tilt a Node(or TransformableNode)object downwards in Sceneform(Ar Core)?
  • When to use RTL and LTR?
  • How to create a tab view (category) similar to instagram's explore tab
  • Glide, RecyclerView: Glide returns the same picture over and over again even with different data inputs
  • how to stop open activity while splash screen killed
  • Changing the Color of the Dynamically loaded Buttons onclick
  • Listview: Add arrows as dividers
  • Show confirmation on back/up in Fragment with Navigation Architecture Component
  • How to find the corresponding maven artifact/gradle module of an Android class from the API Docs?
  • ZXing 3.6.0 in portrait mode?
  • Can't use Subversion command line client: svn The path to the Subversion executable is probably wrong android
  • how to set spinner list value first position showing empty
  • When using PersistableBundle in onCreate, it shows me a blank page
  • Failed to resolve Bintray dependency
  • jacoco code coverage not working for Android applications
  • How to change the color of the Android scroll bumper
  • Why run Handler in main Looper thread
  • Android Studio combined chart crashes
  • Setting suggested width and height to a custom view in android
  • How to set input type and format in EditText using kotlin?
  • how to define Android Oncreate optionmenu
  • Exception on orientation change from two-pane mode to one-pane mode
  • How to access members of nested struct and assign them the values read from device tree?
  • How to measure upload progress of a huge String with Retrofit 2?
  • Runtime app localization doesn't work with app bundles
  • How create View and Putting TextView inside it in kotlin
  • how to integrate app action using actions.xml?
  • ConstraintLayout - center TextView in the root but don't override Button
  • Android Studio Text not conforming to layout_margin when I run App on Emulator
  • verifyReleaseResources apk release - react native
  • My app is not visible in share dialog even with intent filters in place
  • How to use cache or local storage?
  • Unhandled Exception in Recycler view xamarin
  • Android Workmanger PeriodicWorkRequest API work only once?
  • Using Touch ID or Face ID without storing user biometrics
  • React Native 3 button and 3 Modal
  • Token Expiration after 1 Hour in Authentication using Retrofit 2 and Logging Interceptor
  • JNI DETECTED ERROR IN APPLICATION: JNI NewGlobalRef called with pending exception java.lang.ClassNotFoundException:
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org