我想使用SimpleAdapter作为给定代码在listview ..i制作listview上的按钮上制作click listner ...
SimpleAdapter adapter = new SimpleAdapter(
UserBookmarks.this, bookmarksList,
R.layout.list_view_boookmarks, new String[] { BOOKMARK_NAME , BOOKMARK_CATEGORY , BOOKMARKS_RATTING_BAR, BOOKMARKS_REVIEW_TOTAL , BOOKMARKS_CITY }, new int[] { R.id.business_name , R.id.business_category , R.id.ratting, R.id.review_count,R.id.business_city });
adapter.setViewBinder(new SimpleAdapter.ViewBinder() {
@Override
public boolean setViewValue(View view, Object data, String textRepresentation)
{
if (view.getId() == R.id.removeBookmark)
{
Button b=(Button) view;
b.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("HIiiiiiiiiiii", "Button clickeddddddddd");
Toast.makeText(getApplicationContext(), "Click listner called", Toast.LENGTH_SHORT).show();
}
});
return true;
}
return false;
}
});
setListAdapter(adapter);
但onclick listner没有处理此代码....我已经尝试了太多但无法解决这个问题....如果anyoone得到了PLZ答案... 以及如何知道用户点击了哪个按钮ID ..意见列表位置...
答案 0 :(得分:3)
我认为这个问题是由于这个ID"删除书签"。
答案 1 :(得分:3)
检查以下代码
SimpleAdapter adapter = new SimpleAdapter(UserBookmarks.this, bookmarksList,
R.layout.list_view_boookmarks, new String[] { BOOKMARK_NAME , BOOKMARK_CATEGORY , BOOKMARKS_RATTING_BAR, BOOKMARKS_REVIEW_TOTAL , BOOKMARKS_CITY ,**BUTTONLABEL**}, new int[] { R.id.business_name , R.id.business_category , R.id.ratting, R.id.review_count,R.id.business_city ,**R.id.removeBookmark**});
在代码中添加粗体字段 Click here for code Help