我有一个自定义列表项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
,但我没有这样的东西,我不知道它是什么。对不起我的无知。
答案 0 :(得分:2)
您可以浏览本教程以创建自定义Adapter
,您可以在其中获取点击Button
的内容:
http://www.survivingwithandroid.com/2012/10/android-listview-custom-adapter-and.html
http://www.journaldev.com/10416/android-listview-with-custom-adapter-example-tutorial