CodeSolution

Please wait...

How We Can Make AdapterViewFlipper In Android

@AdapterViewFlipper   @ Custom-Adapter   @ BaseAdapter   

First Create New Empty Project
 

  • After That Create This Code In activity_main.xml.
<AdapterViewFlipper
   android:layout_width="wrap_content"
   android:layout_height="200dp"
   android:id="@+id/AdapterViewFlipper"
   android:flipInterval="2000"
   android:background="#03fcfc"
   android:layout_centerHorizontal="true">
</AdapterViewFlipper>
  • ?After That Create The New Layout Page For Controler.
<ImageView
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:src="@drawable/hdfc"
       android:id="@+id/imageView"/>

 

  • ?After That Create The New Java  Page For Custom Adapter.
class CustomAdapter extends BaseAdapter
{
   @Override
   public int getCount() {
       return image.length;
   }
   @Override
   public Object getItem(int i) {
       return null;
   }
   @Override
   public long getItemId(int i) {
       return 0;
   }
   @Override
   public View getView(int i, View view, ViewGroup viewGroup)
   {
       view=getLayoutInflater().inflate(R.layout.flipper_item,null);
       ImageView imageView=view.findViewById(R.id.imageView);
       imageView.setImageResource(image[i]);
       return view;
   }
}
  • ?After That Create MainActivity.java code.
public class MainActivity extends AppCompatActivity
{
AdapterViewFlipper adapterViewFlipper;
int[] image={R.drawable.hdfc,R.drawable.sbi,R.drawable.skip,R.drawable.gmail};
@Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
adapterViewFlipper=findViewById(R.id.AdapterViewFlipper);
CustomAdapter adapter=new CustomAdapter();
adapterViewFlipper.setAdapter(adapter);
adapterViewFlipper.setAutoStart(true);
}
}

Comments 0

Reply