user3032316
user3032316

Reputation: 9

how to add edit and delete button to ListView in android?

i am new in android environment. I am trying to develop an app which retrieve data from data base fetching and all other ok but i want to pass edit and delete button to each listed informaton i have no idea how to pass create and pass button to each listed row.

Upvotes: 1

Views: 1920

Answers (1)

Mushirih
Mushirih

Reputation: 451

In your MyRecyclerviewAdapter,add your buttons in the on Bind method

    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);

            }

        }

Upvotes: 1

Related Questions