Good day. Implemented some kind of store. There is a template containing ImageView and two TextView . Data from the database is pushed into these View with the help of CursorLoader . When you click on View in the database, the product field is updated, which means that the product was purchased (zero or one). Up to this point, everything works well. How do I process the data when the store is loaded? It is necessary to do this: if a product has a unit in the database, then View not clickable.
public class ShopActivity extends AppCompatActivity implements LoaderCallbacks<Cursor>{ SimpleCursorAdapter scAdapter; ListView lvData; DBHelper dbHelper; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_shop2); dbHelper = new DBHelper(this); String[] from = new String[] { DBHelper.ITEMS_IMAGE, DBHelper.ITEMS_NAME, DBHelper.ITEMS_COST }; int[] to = new int[] { R.id.radioImageIV, R.id.radioDescriptionTV, R.id.radioCostTV}; scAdapter = new SimpleCursorAdapter(this, R.layout.shop_item_radio, null, from, to, 0); lvData = (ListView) findViewById(R.id.lvData); lvData.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { view.setClickable(false); new ProgramManager(Shop2Activity.this).setBought(view); //ΠΎΠ±Π½ΠΎΠ²Π»ΡΠ΅Ρ Π·Π°ΠΏΠΈΡΡ Π² ΠΠ } }); lvData.setAdapter(scAdapter); getSupportLoaderManager().initLoader(0, null, this); } @Override public Loader<Cursor> onCreateLoader(int id, Bundle bundle) { return new MyCursorLoader(this, dbHelper); } @Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { scAdapter.swapCursor(cursor); } static class MyCursorLoader extends CursorLoader { DBHelper dbHelper; public MyCursorLoader(Context context, DBHelper db) { super(context); this.dbHelper = db; } @Override public Cursor loadInBackground() { SQLiteDatabase db = dbHelper.getReadableDatabase(); Cursor cursor = db.query(DBHelper.ITEMS_TABLE_NAME, null, null, null, null, null,null); try { TimeUnit.SECONDS.sleep(2); } catch (InterruptedException e) { e.printStackTrace(); } return cursor; } } shop_item_radio.xml
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" android:animateLayoutChanges="true" android:background="@drawable/border_shop" android:fillViewport="true" android:isScrollContainer="true"> <ImageView android:id="@+id/radioImageIV" android:layout_width="80dp" android:layout_height="80dp" android:layout_marginBottom="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:background="@drawable/border" android:padding="4dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:srcCompat="@drawable/radio" /> <TextView android:id="@+id/radioDescriptionTV" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginEnd="8dp" android:layout_marginStart="4dp" android:layout_marginTop="8dp" android:textAlignment="textStart" android:textColor="#004D40" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/radioImageIV" app:layout_constraintTop_toTopOf="parent" /> <TextView android:id="@+id/radioCostTV" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:drawableLeft="@drawable/ic_money_24dp" android:text="10000" android:textAlignment="gravity" android:textColor="#004D40" android:textSize="18sp" android:textStyle="bold" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="@+id/radioDescriptionTV" /> </android.support.constraint.ConstraintLayout>
deprecatedmethods - R1zenCREATE TABLE "items" ( "_id" INTEGER PRIMARY KEY AUTOINCREMENT, "itemName" TEXT, "itemDescriptions" TEXT, "itemCost" INTEGER, "itemImage" TEXT, "isBought" INTEGER );- R1zen 2:42 pmR.layout.shop_item_radio- R1zen