Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Use StackView in Android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 204
    Comment on it

    StackView is used to display views in StackView. StackView is added from API level 11. 

     

    Steps to implement StackView

    1. add StackView in layout .

        <StackView
            android:id="@+id/stackView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    2. Find StackView in Java class file.

     StackView stackView = (StackView)findViewById(R.id.stackView);

    3.  Create Base Adapter class for StackView.

    public class StackAdapter extends BaseAdapter {
    
        private final int[] mImages = {R.drawable.eggs, R.drawable.gurudwara, R.drawable.heart, R.drawable.stars, R.drawable.universe};
        private final Context mContext;
    
        public StackAdapter(Context context) {
            mContext = context;
        }
    
        @Override
        public int getCount() {
            return mImages.length;
        }
    
        @Override
        public Object getItem(int position) {
            return mImages[position];
        }
    
        @Override
        public long getItemId(int position) {
            return 0;
        }
    
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = convertView;
            if (view == null) {
                LayoutInflater vi = (LayoutInflater)
                        mContext.getSystemService(
                                Context.LAYOUT_INFLATER_SERVICE);
                view = vi.inflate(R.layout.item_view, null, false);
            }
            ImageView imageView = (ImageView) view.findViewById(
                    R.id.imageview);
            imageView.setImageResource(mImages[position]);
            return view;
        }
    }
    

    4. Create Adapter Instance and set adapter to StackView.

     StackAdapter adapter = new StackAdapter(this);
            stackView.setAdapter(adapter);

    Happy Coding :)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: