How to move the first position of the image to the second position in the listView on the button click on android

advertisements

How to move the first position of image to second position in ListView on Button click,so that last position of image will comes to first position.

my tried codes below;

public class MainActivity extends AppCompatActivity {

private int[] images = {R.drawable.img1,R.drawable.img2,R.drawable.img3,R.drawable.img4,R.drawable.img5};
ArrayList<ImageModel> imageModels;

@Override
protected void onCreate (Bundle savedInstanceState) {
    super.onCreate (savedInstanceState);
    setContentView (R.layout.activity_main);

    imageModels = new ArrayList<ImageModel> ();
    for (int i = 0; i < images.length; i++) {
        ImageModel imgMode = new ImageModel ();
        imgMode.setImageId (images[i]);
        imageModels.add (imgMode);
        Log.d ("chk",""+images[i]);
    }

    ListView lstView = (ListView)findViewById (R.id.lst_view);
    lstView.setAdapter (new BaseAdapterr(MainActivity.this,imageModels));

    Button btnClick = (Button)findViewById (R.id.btn_click);
    btnClick.setOnClickListener (new View.OnClickListener () {
        @Override
        public void onClick (View v) {
           for (int i=0 ;i < imageModels.size ();i++){
           }
        }
    });
}}


Try using getting the object index and then use setIndex or sth like that for changing index.

Tarik.