vinay Maneti
vinay Maneti

Reputation: 1451

Naviagtion Drawer Add buttons on list view in android

I want to add buttons in each list view of the navigation Drawer. How can we add the button over there can any body provide example/sample code. I took the sample example from Android Developers..

Thanks In Advance

Upvotes: 0

Views: 289

Answers (1)

Naveen Kumar Kuppan
Naveen Kumar Kuppan

Reputation: 1442

You will just use this answer I explained how to design custom listView.... In the below class i used two textview for the replacement of that two you just use a Two

Button in tha layout and use this custom adapter

like....

CustomAdapter mAdapter = new CustomAdapter(this, R.layout.listitem, mListItems);
mPullRefreshListView.setAdapter(mAdapter);

and then use this code...

public class CustomAdapter extends ArrayAdapter<Sample> {

public ArrayList<Sample> mlist;
public Context context;
public LayoutInflater inflater;

public CustomAdapter(Context context, int resource, ArrayList<Sample> mlist) {
    super(context, resource);
    this.mlist = mlist;
    this.context = context;
    inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

@Override
public int getPosition(Sample item) {
    return super.getPosition(item);
}

@Override
public Sample getItem(int position) {
    return mlist.get(position);
}

@Override
public int getCount() {
    return mlist.size();
}

@Override
public long getItemId(int position) {
    return super.getItemId(position);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    convertView = inflater.inflate(R.layout.listitem, null);
    TextView text1 = (TextView) convertView.findViewById(R.id.item1);
    TextView text2 = (TextView) convertView.findViewById(R.id.item2);
    text1.setText(mlist.get(position).getListitem1());
    text2.setText(mlist.get(position).getListitem2());
    text2.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // you just put your Logic here And use this custom adapter to
            // load your Data By using this particular custom adapter to
            // your listview

        }
    });
    return convertView;
}

}

All the best

Upvotes: 1

Related Questions