0

I have a custom list item XML with 2 Buttons and I want to get when one is clicked (and a way of knowing which one). My ListView is made with data from a database. This is what I use for populating the list:

private DBManager manager;
private Cursor cursor;
private ListView lista;
SimpleCursorAdapter adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.m_home_layout);

    manager = new DBManager(this);
    lista = (ListView) findViewById(R.id.listview);



    String[] from = new String[]{manager.CN_NAME, manager.CN_DESCRIPTION, manager.CN_TIME, manager.CN_DAY};
    int[] to = new int[] {R.id.list_title, R.id.list_description, R.id.list_time, R.id.list_day};
    cursor = manager.cargarCursorData("data");
    adapter = new SimpleCursorAdapter(this, R.layout.list_item, cursor, from, to,0);
    lista.setAdapter(adapter);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);



    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
        this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

}

I've seen people saying that you have to use bindView but I don't have anything like that and I don't know what it is. Sorry for my ignorance.

1
  • you should move on to recyclerview, it's much more flexible. Commented Mar 29, 2017 at 5:28

1 Answer 1

2

You can go through this tutorials for Creating Custom Adapter, in which you can get the which Button is clicked:

http://www.survivingwithandroid.com/2012/10/android-listview-custom-adapter-and.html

http://www.journaldev.com/10416/android-listview-with-custom-adapter-example-tutorial

Sign up to request clarification or add additional context in comments.

1 Comment

I'll check them out, second one seems to be exactly what I need. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.