如何向ListView添加按钮侦听器?

时间:2017-03-28 21:53:42

标签: java android

我有一个自定义列表项XML,其中包含2个Buttons,我想在点击一个时获取(以及了解哪一个)。我的ListView来自数据库中的数据。这是我用来填充列表的内容:

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

}

我见过有人说你必须使用bindView,但我没有这样的东西,我不知道它是什么。对不起我的无知。

1 个答案:

答案 0 :(得分:2)