本文实例为大家分享了Android实现购物车加减商品操作的具体代码,供大家参考,具体内容如下
MainActivity.java
public class MainActivity extends AppCompatActivity { private Addand mAddand; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mAddand= findViewById(R.id.add); mAddand.setOnNumberChangedListener(new Addand.OnNumberChangedListener() { @Override public void OnNumberChanged(int vs) { Toast.makeText(MainActivity.this, vs+"", Toast.LENGTH_SHORT).show(); } }); } }activity_main.xml
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:orientation="horizontal"> <fanruiqi./apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <ImageView android:id="@+id/image1" android:layout_width="20dp" android:layout_height="20dp" android:src="@drawable/ic_launcher_background"/> <TextView android:id="@+id/text" android:layout_width="50dp" android:layout_height="20dp" android:gravity="center" android:text="1"/> <ImageView android:id="@+id/image2" android:layout_width="20dp" android:layout_height="20dp" android:src="@drawable/ic_launcher_background"/></LinearLayout>以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。