I'm working in Java code, but I can not figure out how to shuffle my images and text. Here is all of my coding. They are in different classes so I will post them separately. This is in Android Studio.
This is my ImageandTextAdapter code:
public class ImageAndTextAdapter extends ArrayAdapter<String> {
private LayoutInflater mInflater;
private String[] mStrings;
private TypedArray mIcons;
private int mViewResourceId;
public ImageAndTextAdapter (Context ctx, int ViewResourceId, String[] strings, TypedArray icons) {
super(ctx, ViewResourceId, strings);
mInflater = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mStrings = strings;
mIcons = icons;
mViewResourceId = ViewResourceId;
}
@Override
public int getCount () { return mStrings.length; }
@Override
public String getItem(int position) {return mStrings[position]; }
@Override
public long getItemId(int position) {return 0; }
@Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = mInflater.inflate(mViewResourceId, null);
ImageView iv = (ImageView) convertView.findViewById(R.id.imageView);
iv.setImageDrawable(mIcons.getDrawable(position));
TextView tv = (TextView)convertView.findViewById(R.id.textView);
tv.setText(mStrings[position]);
return convertView;
}
}
This is my picture array code:
<resources>
<array name="card_faces">
<item>@drawable/b01</item>
<item>@drawable/b02</item>
<item>@drawable/b03</item>
<item>@drawable/b04</item>
<item>@drawable/b05</item>
<item>@drawable/b06</item>
<item>@drawable/b07</item>
<item>@drawable/b08</item>
</array>
</resources>
This is my main activity code:
public class MainActivity extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Context context = getApplicationContext();
Resources resources = context.getResources();
String[] card = {"Blue1", "Blue2", "BlueSnake", "Blue4", "Blue5", "Blue6", "Blue7", "BlueHawk"};
TypedArray card_faces = resources.obtainTypedArray(R.array.card_faces);
setListAdapter(new ImageAndTextAdapter (context, R.layout.secondary_layout, card, card_faces));
}
}
I want to shuffle my pictures which are set in the array, but I am not able to with the Collections.shuffle command. If you know of a way that I could shuffle my pictures using a different and simple method, please help.