Guest User

Untitled

a guest
Jan 24th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. Spinner mySpinner = (Spinner) findViewById(R.id.spinner1);
  2. mySpinner.setDropDownWidth(900);
  3. mySpinner.setSelection(0);
  4. mySpinner.setAdapter(new MyAdapter(HomeActivity.this, R.layout.list_circle, Languages));
  5.  
  6. public class MyAdapter extends ArrayAdapter {
  7.  
  8. public MyAdapter(Context context, int textViewResourceId,
  9. String[] objects) {
  10. super(context, textViewResourceId, objects);
  11. }
  12.  
  13. public View getCustomView(final int position, View convertView,
  14. ViewGroup parent) {
  15.  
  16. LayoutInflater inflater = getLayoutInflater();
  17. View layout = inflater.inflate(R.layout.list_circle, parent, false);
  18.  
  19. TextView tvCircleName = (TextView) layout.findViewById(R.id.tvCircleName);
  20.  
  21.  
  22. tvCircleName.setText(Languages[position]);
  23. ImageView ivIcon = (ImageView) layout.findViewById(R.id.ivIcon);
  24. ImageView ivSetting = (ImageView) layout.findViewById(R.id.ivSetting);
  25. layout.setOnClickListener(new View.OnClickListener() {
  26. @Override
  27. public void onClick(View v) {
  28. HelperClass helperClass = new HelperClass(getContext());
  29. helperClass.showToast(Languages[position]);
  30. }
  31. });
  32. return layout;
  33. }
  34.  
  35. @Override
  36. public View getDropDownView(int position, View convertView,
  37. ViewGroup parent) {
  38. return getCustomView(position, convertView, parent);
  39. }
  40. @Override
  41. public View getView(int position, View convertView, ViewGroup parent) {
  42. return getCustomView(position, convertView, parent);
  43. }
  44. }
  45.  
  46. <Spinner
  47. android:id="@+id/spinner1"
  48. android:layout_width="wrap_content"
  49. android:layout_height="match_parent"
  50. android:drawSelectorOnTop="true"
  51. android:overlapAnchor="false"/>
Add Comment
Please, Sign In to add comment