如何在android中添加编辑和删除按钮到ListView?

时间:2015-05-29 14:45:22

标签: android listview button

我是android环境中的新手。我正在尝试开发一个应用程序,从数据库提取和其他所有其他确定,但我想通过编辑和删除按钮到每个列出的信息,我不知道如何传递创建和传递按钮到每个列出的行。

1 个答案:

答案 0 :(得分:1)

在MyRecyclerviewAdapter中,在on Bind方法中添加按钮

    public  class ViewHolder extends RecyclerView.ViewHolder  {

            TextView trans;
            TextView from;
            TextView to;
            TextView est_dest;
            public ViewHolder(View itemView) {
                super(itemView);
                trans=(TextView)itemView.findViewById(R.id.trans);
                from=(TextView)itemView.findViewById(R.id.from);
                to=(TextView)itemView.findViewById(R.id.to);
                est_dest=(TextView)itemView.findViewById(R.id.est_distance);

            }

        }


//If you are using a listview,you can add the button in your adapter

 @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            ViewHolder holder;
            if (convertView == null) {
//view you wat to show in the list item
                convertView = View.inflate(ListCred.this, R.layout.cred_item_layout, null);


            return convertView;
        }
 private class ViewHolder {
            public ImageView imageView;
            public TextView name;
            public TextView pos;

            private ViewHolder(View v) {
//instantiate your buttons
                imageView = (ImageView) v.findViewById(R.id.imageView);
                name = (TextView) v.findViewById(R.id.name);
                pos = (TextView) v.findViewById(R.id.pos);

            }

        }