daily pastebin goal
83%
SHARE
TWEET

Untitled

a guest May 25th, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class MainActivity extends Activity implements AdapterView.OnItemClickListener {
  2.  
  3. String[] nome_membros;
  4. TypedArray pic_perfil;
  5. String[] status;
  6. String[] tipo_contactos;
  7.  
  8. List<RowItem> rowItems;
  9. ListView mylistview;
  10.  
  11. @Override
  12. protected void onCreate(Bundle savedInstanceState) {
  13.     super.onCreate(savedInstanceState);
  14.     setContentView(R.layout.activity_main);
  15.  
  16.     rowItems = new ArrayList<RowItem>();
  17.  
  18.     nome_membros = getResources().getStringArray(R.array.Nome_Membros);
  19.  
  20.     pic_perfil = getResources().obtainTypedArray(R.array.Fotos_perfil);
  21.  
  22.     status = getResources().getStringArray(R.array.status);
  23.  
  24.     tipo_contactos = getResources().getStringArray(R.array.tipo_contacto);
  25.  
  26.     for (int i = 0; i < nome_membros.length; i++) {
  27.         RowItem item = new RowItem(nome_membros[i],
  28.                 pic_perfil.getResourceId(i, -1), status[i],
  29.                 tipo_contactos[i]);
  30.         rowItems.add(item);
  31.     }
  32.  
  33.     mylistview = (ListView) findViewById(R.id.list);
  34.     CustomAdapter adapter = new CustomAdapter(this, rowItems);
  35.     mylistview.setAdapter(adapter);
  36.  
  37.     mylistview.setOnItemClickListener(this);
  38.  
  39. }
  40.    
  41. <resources>
  42. <string name="app_name">Listview Contactos</string>
  43.  
  44. <!--Nomes-->
  45. <string-array name="Nome_Membros">
  46.     <item>Paulo</item>
  47.     <item>Bito</item>
  48.     <item>Rio</item>
  49.     <item>Zé</item>
  50.     <item>Tiago</item>
  51.     <item>Ricardo</item>
  52.     <item>Tomé</item>
  53. </string-array>
  54.  
  55. <!--Fotos de perfil-->
  56. <array name="Fotos_perfil">
  57.     <item>@drawable/foto1</item>
  58.     <item>@drawable/foto2</item>
  59.     <item>@drawable/foto3</item>
  60.     <item>@drawable/foto4</item>
  61.     <item>@drawable/foto5</item>
  62.     <item>@drawable/foto6</item>
  63.     <item>@drawable/foto7</item>
  64. </array>
  65.  
  66. <!--status-->
  67. <string-array name="status">
  68.     <item>Ocupado</item>
  69.     <item>Disponivel</item>
  70.     <item>Offline</item>
  71. </string-array>
  72.  
  73. <!--Tipo de contacto-->
  74. <string-array name="tipo_contacto">
  75.     <item>Telemovel</item>
  76.     <item>Fixo</item>
  77. </string-array>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top