正式にコードを学習してからわずか3ヶ月ですが、興味深いのです。 現在、私はシンプルなデータベースサンプルコードからアンドロイドスタジオを使って簡単な販売管理アンドロイドアプリケーションを作成しようとしています。 は、私は次のことを可能にするために、右のJavaコードを設定するに立ち往生しています:データベースによって設定されたアイテムにクリックリスナーを設定する
- ユーザーがチェックボックス(@ + ID /選択)をクリックして購入する製品を選択し
- 彼は製品の数量を入力します例5(@ id/quantity)を購入する
- アプリケーションは、製品の価格(@ + id/price)と数量を合計し、合計(@ + id/total)を表示することになっています。次のよう
個々の項目の形式は次のとおりです。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="@dimen/activity_margin">
<CheckBox
android:id="@+id/choice"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
<TextView
android:id="@+id/name"
android:layout_width="70dp"
android:layout_height="match_parent"
android:text="Soda" />
<TextView
android:id="@+id/price"
android:layout_width="70dp"
android:layout_height="match_parent"
android:text="1000/=" />
<TextView
android:layout_width="10dp"
android:layout_height="match_parent"
android:text="*" />
<EditText
android:id="@+id/quantity"
android:layout_width="80dp"
android:layout_height="match_parent"
android:hint="amount"
android:inputType="number" />
<TextView
android:layout_width="10dp"
android:layout_height="match_parent"
android:text="=" />
<TextView
android:id="@+id/total"
android:layout_width="80dp"
android:layout_height="match_parent"
android:hint="total" />
</LinearLayout>
(そのコードを短縮し、今でも最も重要な部分を表示するように、私はいくつかの研磨のコードを削除しました)。 製品の名前と価格は、Contract、Dbhelper、Provider、およびCursor Adapterのような通常のJavaファイルを使用して作成されたSQLiteデータベースによって生成されます。 ユーザーが別のアクティビティに製品名と価格を入力し、さらに50社の製品よりも、すべての製品は、以下のリストビューレイアウトにその形式を使用して移入されます
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SalesActivity2">
<ListView
android:id="@+id/sales_list"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</RelativeLayout>
これまでのところ、他のすべてが正常に動作します。ユーザーは、選択した数の商品を入力することができます。データベースは、フォーマットおよびレイアウトに従ってリストビュー上に製品を配置することができます。 SalesActivity2に適切なJavaコードを設定して、これらの計算を有効にし、合計金額を表示することが課題です。 クリックリスナーを設定する必要がありますが、ユーザーが複数の場所、つまりボタンをクリックする必要があり、購入する製品の数量を設定する必要があるため、設定する正しい方法はわかりません。 私は最後の5日間、答えを探していましたが、私が得たすべての答えに、アプリケーションにエラーがあるか何もしない何らかの行方不明がありました。 私はその挑戦をどのようにして解決するのか、あなたのご提案をお待ちしております。 ありがとうございます。
ありがとう、私はそれを試してみましょう。 – Mika369