单个TextBox计算

时间:2016-05-18 10:29:40

标签: android-layout listview dialog onitemclicklistener

我需要能够编辑TextBox的值,这样如果我输入一个小于850的值,它就会从中减去并存储在文本框中。谢谢你 This is the output of the code.

MainActivity.java

    public class Adapter extends RecyclerView.Adapter<Viewholder> {
    private List<Students> studentsList;
    private Context context;

    public Adapter(Context context, List<Students> studentsList){
        this.context=context;
        this.studentsList=studentsList;
    }
    @Override
    public Viewholder onCreateViewHolder(ViewGroup parent, int viewType) {
        View layoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.single_item,null);
        Viewholder hld = new Viewholder(layoutView);
        return hld;
    }

    @Override
    public void onBindViewHolder(Viewholder holder, int position) {
        holder.name.setText(studentsList.get(position).getName());
        holder.amount.setText(Integer.toString(studentsList.get(position).getAmt()));
    }

    @Override
    public int getItemCount() {
        return this.studentsList.size();
    }
}

Adapter.java

    public class Viewholder extends RecyclerView.ViewHolder {


    public TextView name;
    public EditText amount;

    public Viewholder(View v) {
        super(v);
        name = (TextView) v.findViewById(R.id.Name);
        amount = (EditText) v.findViewById(R.id.et_amount);


    }
}

Viewholder.java

    <?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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.zaraki.calculationapp.MainActivity">

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/recycler_view"
        android:scrollbars="vertical"></android.support.v7.widget.RecyclerView>
</RelativeLayout>

activity_main.xml中

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/Name"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:text="Prashant Dhimal"
        android:textSize="20sp"
        android:layout_marginTop="20dp" />


    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="number"
        android:ems="10"
        android:id="@+id/et_amount"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/Name"
        android:layout_toEndOf="@+id/Name"
        android:hint="850"
        android:onClick="onClick"
        android:layout_marginTop="20dp"/>

</RelativeLayout>

single_item.xml

resize

0 个答案:

没有答案