Мне просто нужно получить строки, которые являются текстовыми представлениями всего, что связано с элементом сетки, на который я нажимаю.
getItemAtPosition дает мне ряд случайных чисел, таких как: Collectable @ c88c9b, и SELECT * FROM TABLE_COLLECTION просто передает мне каждое имя в каждой строке, когда мне нужно только то, что я нажимаю, пожалуйста, пожалуйстапомогите мне, я так близок к завершению.
фрагмент с gridview
public class CollectionFragment extends Fragment {
GridView gridView;
ArrayList<Collectable> list;
CollectionListAdapter adapter = null;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setHasOptionsMenu (true);
// inflater.inflate(R.layout.fragment_collection, container, false);
View view = inflater.inflate(R.layout.fragment_collection, null);
gridView = (GridView) view.findViewById(R.id.gridView);
list = new ArrayList<>();
//if (gridView != null) {
adapter = new CollectionListAdapter(getActivity().getApplicationContext(), R.layout.images_carousel, list);
gridView.setAdapter(adapter);
//}
final Cursor cursor = ScannerPopup.sqLiteHelper.getData("SELECT * FROM TABLE_COLLECTION");
list.clear();
while(cursor.moveToNext()) {
int id = cursor.getInt(0);
String name = cursor.getString(1);
String box = cursor.getString(2);
String prod = cursor.getString(3);
String date = cursor.getString(4);
String store = cursor.getString(5);
String country = cursor.getString(6);
byte[] image = cursor.getBlob(7);
list.add(new Collectable(name, box, prod, date, store, country, image, id));
}
adapter.notifyDataSetChanged();
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long l) {
String clickedText = parent.getItemAtPosition(position).toString();
Cursor c = ScannerPopup.sqLiteHelper.getData("SELECT * FROM TABLE_COLLECTION");
while(c.moveToNext()) {
int id = c.getInt(0);
String name = c.getString(1);
String box = c.getString(2);
String prod = c.getString(3);
String date = c.getString(4);
String store = c.getString(5);
String country = c.getString(6);
byte[] image = c.getBlob(7);
Log.d("meme", clickedText);
Log.d("tag2", name);
}
}
});
Адаптер списка коллекций
public class CollectionListAdapter extends BaseAdapter {
private Context context;
private int layout;
private ArrayList<Collectable> collectablesList;
public CollectionListAdapter(Context context, int layout, ArrayList<Collectable> collectablesList) {
this.context = context;
this.layout = layout;
this.collectablesList = collectablesList;
}
@Override
public int getCount() {
return collectablesList.size();
}
@Override
public Object getItem(int position) {
return collectablesList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
private class ViewHolder {
ImageView imageView;
TextView txtName, txtBox, txtProd, txtDate, txtStore, txtCountry;
}
@Override
public View getView(int position, View view, ViewGroup viewGroup) {
View row = view;
ViewHolder holder = new ViewHolder();
if (row == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(layout, null);
holder.txtName = (TextView) row.findViewById(R.id.txtName);
holder.txtBox = (TextView) row.findViewById(R.id.txtBox);
holder.txtProd = (TextView) row.findViewById(R.id.txtProd);
holder.txtDate = (TextView) row.findViewById(R.id.txtDate);
holder.txtStore = (TextView) row.findViewById(R.id.txtStore);
holder.txtCountry = (TextView) row.findViewById(R.id.txtCountry);
holder.imageView = (ImageView) row.findViewById(R.id.imgCollectable);
row.setTag(holder);
}
else {
holder = (ViewHolder) row.getTag(); //problem child
}
Collectable collectable = collectablesList.get(position);
holder.txtName.setText(collectable.getName());
holder.txtBox.setText(collectable.getBox());
holder.txtProd.setText(collectable.getProd());
holder.txtDate.setText(collectable.getDate());
holder.txtStore.setText(collectable.getStore());
holder.txtCountry.setText(collectable.getCountry());
byte[] collectableImage = collectable.getImage();
Bitmap bitmap = BitmapFactory.decodeByteArray(collectableImage, 0, collectableImage.length);
holder.imageView.setImageBitmap(bitmap);
return row;
}
}
images карусель
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="300dp"
android:layout_height="400dp"
android:layout_gravity="center"
android:layout_marginTop="20dp">
<ImageView
android:id="@+id/imgCollectable"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
app:srcCompat="@drawable/defaultimg" />
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@drawable/ic_favorite_border"
android:layout_alignRight="@id/imgCollectable"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"/>
<View
android:layout_width="match_parent"
android:layout_height="20dp"
android:background="@color/darkgrey"
android:alpha="0.7"
android:layout_alignParentBottom="true"/>
<TextView
android:id="@+id/txtName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="No Name Inserted"
android:textAlignment="center"
android:fontFamily="@font/regular"
android:textColor="@color/white"
android:textSize="14sp"
android:layout_alignParentBottom="true"/>
<!--android:textColor="#00000000"-->
<TextView
android:id="@+id/txtProd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="TextView"
android:textColor="#00000000"/>
<TextView
android:id="@+id/txtBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="TextView"
android:textColor="#00000000"/>
<TextView
android:id="@+id/txtDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="TextView"
android:textColor="#00000000"/>
<TextView
android:id="@+id/txtStore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="TextView"
android:textColor="#00000000"/>
<TextView
android:id="@+id/txtCountry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="TextView"
android:textColor="#00000000"/>
</RelativeLayout>
</LinearLayout>
getData () метод
public void insertData(String name, String box, String prod, String date, String store, String country, byte[] image) {
SQLiteDatabase database = getWritableDatabase();
String sql = "INSERT INTO TABLE_COLLECTION VALUES (NULL, ?, ?, ?, ?, ?, ?, ?) ";
SQLiteStatement statement = database.compileStatement(sql);
statement.clearBindings();
statement.bindString(1, name);
statement.bindString(2, box);
statement.bindString(3, prod);
statement.bindString(4, date);
statement.bindString(5, store);
statement.bindString(6, country);
statement.bindBlob(7, image);
statement.executeInsert();
}
public Cursor getData(String sql) {
SQLiteDatabase database = getReadableDatabase();
return database.rawQuery(sql, null);
}
без ошибок, просто нужна помощь:)
заранее спасибо