Guest User

Untitled

a guest
Dec 11th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. public void guardar(View view) {
  2.  
  3. Intent i = new Intent( this, MainActivity.class);
  4.  
  5. edit = findViewById(R.id.editText);
  6. String number= edit.getText().toString();
  7. String imagenUri = String.valueOf(getImageUri());
  8.  
  9. i.putExtra("imagen",imagenUri);
  10. i.putExtra("tara", number);
  11.  
  12. startActivity(i);
  13. }
  14.  
  15. peso = extras.getString("tara");
  16. uri = extras.getString("imagen");
  17.  
  18. ArrayList<ImagenesFoto> results = new ArrayList<ImagenesFoto>();
  19.  
  20. ImagenesFoto sr1 = new ImagenesFoto();
  21. sr1.setTaraImagen(peso);
  22. sr1.setRutaImagen(uri);
  23. results.add(sr1);
  24.  
  25.  
  26. grid = view.findViewById(R.id.gridView);
  27. GridViewAdapter gridViewAdapter= new GridViewAdapter(getContext(), results);
  28. grid.setAdapter(gridViewAdapter);
  29.  
  30. public class GridViewAdapter extends BaseAdapter {
  31.  
  32. private ArrayList<ImagenesFoto> searchArrayList;
  33. private LayoutInflater mInflater;
  34.  
  35. GridViewAdapter(Context context, ArrayList<ImagenesFoto> results) {
  36. this.searchArrayList = results;
  37. mInflater = LayoutInflater.from(context);
  38. }
  39.  
  40. @Override
  41. public int getCount() {
  42. return searchArrayList.size();
  43. }
  44.  
  45. @Override
  46. public Object getItem(int position) {
  47. return searchArrayList.get(position);
  48. }
  49.  
  50. @Override
  51. public long getItemId(int position) {
  52. return position;
  53. }
  54.  
  55. @SuppressLint("InflateParams")
  56. @Override
  57. public View getView(int position, View convertView, ViewGroup parent) {
  58. ViewHolder holder;
  59. if (convertView == null) {
  60. convertView = mInflater.inflate(R.layout.grid_item,null);
  61. holder = new ViewHolder();
  62. holder.pesoTara = convertView.findViewById(R.id.pesoTara);
  63. holder.img = convertView.findViewById(R.id.img);
  64.  
  65.  
  66. convertView.setTag(holder);
  67. } else {
  68. holder = (ViewHolder) convertView.getTag();
  69. }
  70.  
  71.  
  72. holder.img.setImageURI(Uri.parse(searchArrayList.get(position).getRutaImagen()));
  73. holder.pesoTara.setText(searchArrayList.get(position).getTaraImagen());
  74.  
  75. return convertView;
  76. }
  77.  
  78. static class ViewHolder {
  79. TextView pesoTara;
  80. ImageView img;
  81. }
  82.  
  83. public class ImagenesFoto {
  84.  
  85. public String rutaImagen;
  86. public String taraImagen;
  87.  
  88.  
  89.  
  90. public String getRutaImagen() {
  91. return rutaImagen;
  92. }
  93.  
  94. public void setRutaImagen(String rutaImagen) {
  95. this.rutaImagen = rutaImagen;
  96. }
  97.  
  98. public String getTaraImagen() {
  99. return taraImagen;
  100. }
  101.  
  102. public void setTaraImagen(String taraImagen) {
  103. this.taraImagen = taraImagen;
  104. }
  105.  
  106. <LinearLayout
  107. android:id="@+id/tab1"
  108. xmlns:android="http://schemas.android.com/apk/res/android"
  109. android:layout_width="match_parent"
  110. android:layout_height="match_parent"
  111. android:orientation="vertical">
  112.  
  113. <ListView
  114. android:id="@+id/gridView"
  115. android:layout_width="match_parent"
  116. android:layout_height="match_parent">
  117. </ListView>
  118.  
  119. <android.support.v7.widget.CardView
  120. xmlns:android="http://schemas.android.com/apk/res/android"
  121. android:layout_width="match_parent"
  122. android:layout_height="wrap_content"
  123. android:layout_margin="5dp"
  124. android:id="@+id/cardView">
  125.  
  126. <LinearLayout
  127. android:layout_width="match_parent"
  128. android:layout_height="match_parent"
  129. android:orientation="vertical"
  130. android:weightSum="10">
  131.  
  132. <ImageView
  133. android:layout_weight="2"
  134. android:id="@+id/img"
  135. android:layout_width="match_parent"
  136. android:layout_height="120dp" />
  137.  
  138. <LinearLayout
  139. android:layout_width="match_parent"
  140. android:layout_height="match_parent"
  141. android:layout_weight="8"
  142. android:orientation="horizontal">
  143.  
  144. <TextView
  145. android:layout_weight="1"
  146. android:id="@+id/textTara"
  147. android:layout_width="wrap_content"
  148. android:layout_height="match_parent"
  149. android:text="Tara"
  150. android:textAlignment="center"
  151. android:textColor="#000" />
  152.  
  153. <TextView
  154. android:layout_weight="1"
  155. android:id="@+id/pesoTara"
  156. android:layout_width="wrap_content"
  157. android:layout_height="match_parent"
  158. android:hint="Tara"
  159. android:textAlignment="center"/>
  160.  
  161. </LinearLayout>
  162.  
  163. </LinearLayout>
Add Comment
Please, Sign In to add comment