如何为recyclerView中的每个imageView添加editText并将其保存到PARSE?

时间:2016-01-22 09:07:31

标签: android parse-platform android-recyclerview buttonclick recycler-adapter

所以在我的recyclerview中,我有一个由CARDVIEW组成的 ImageView,EditText和一个按钮。当我点击按钮时,它会将文本从EditText发送到PARSE.com。我的问题是,我无法将该文本链接到它的ImageView 我想当我打开应用程序时,我可以看到imageView,在底部会有图像的描述。我希望editText是动态的。有人可以指导我吗?

这是XML布局:

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/card_view"
    android:layout_margin="10dp"
    android:layout_marginBottom="30dp"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:id="@+id/linearLayout">


    <ImageView
        android:id="@+id/imageViewRecycler"
        android:background="@color/border"
        android:layout_width="match_parent"
        android:layout_height="380dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true"
        android:contentDescription="TODO"
        />

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/separator"
            android:id="@+id/separator"
            android:layout_above="@+id/firstLine"
            android:layout_alignParentStart="true" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/grey">


            <EditText
                android:id="@+id/firstLineText"
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:layout_alignWithParentIfMissing="true"
                android:gravity="top"
                android:background="@color/colorPrimary"
                android:textSize="16sp"
                android:textColor="@color/colorAccent"
                android:layout_alignParentBottom="true"
                android:layout_alignStart="@+id/linearLayout"
                android:layout_alignParentTop="true" />
        <Button
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="save"
            android:id="@+id/firstLineButton"
            android:layout_gravity="right"
            android:layout_alignParentTop="true"
            android:layout_alignParentEnd="true" />

        </RelativeLayout>
    </LinearLayout>

</android.support.v7.widget.CardView>

这是我的recyclerview适配器:

public class myAdapter extends RecyclerView.Adapter<myAdapter.ViewHolder> {


    LayoutInflater inflater;
    List<imageDescription> data= Collections.emptyList();
    private Context context;
    ViewHolder holder;

    public myAdapter(Context context, List<imageDescription> data){
        this.context=context;
        this.data=data;
    }


    @Override
    public myAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {


        View view=inflater.from(context).inflate(R.layout.custom_layout, parent, false);
             holder= new ViewHolder(view);
        return holder;

    }

    @Override
    public void onBindViewHolder(myAdapter.ViewHolder holder, int position) {


        imageDescription current= data.get(position);


        Glide.with(context)
                .load(current.url)
                .centerCrop()
                .override(500,500)
                .placeholder(R.drawable.whitebackground)
                .into(holder.imageViewRecycler);





        holder.firstLineText.setText(current.firstLine);


    }


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


 public class ViewHolder extends RecyclerView.ViewHolder {

        ImageView imageViewRecycler;

        EditText firstLineText;

        Button firstLineButton;


        public ViewHolder(final View itemView) {
            super(itemView);


            imageViewRecycler=(ImageView)itemView.findViewById(R.id.imageViewRecycler);

            firstLineText=(EditText)itemView.findViewById(R.id.firstLineText);

            firstLineButton=(Button)itemView.findViewById(R.id.firstLineButton);


                firstLineButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                     ParseObject obj= new ParseObject("newMessage");

                     obj.put("imageDetail",firstLineText.getText());

                     obj.saveInBackground();


                    }
                });
        }


    }

}

0 个答案:

没有答案