如何使用列表视图适配器中的单击按钮打开菜单上下文 Android?
我尝试了我的代码,但没有显示菜单上下文,
代码
public View getView(int position, View convertView, ViewGroup parent) {
vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.tulisan_komentar_list_item,parent, false);
LinearLayout content_favorite= (LinearLayout)vi.findViewById(R.id.content_favorite);
final TextView date_komentar = (TextView)vi.findViewById(R.id.date_komentar); // artist name
final TextView isi_komentar = (TextView)vi.findViewById(R.id.isi_komentar); // duration
final TextView nama_komentar = (TextView)vi.findViewById(R.id.nama_komentar); // duration
final TextView id_tulisan_komentar = (TextView)vi.findViewById(R.id.id_tulisan_komentar); // duration
final ImageButton act_komentar = (ImageButton)vi.findViewById(R.id.act_komentar);
ImageView thumb_image=(ImageView)vi.findViewById(R.id.avatar_komentar); // thumb image
HashMap<String, String> tulisan = new HashMap<String, String>();
tulisan = data.get(position);
// Setting all values in listview
date_komentar.setText(tulisan.get(ContentCommentActivity.TAG_DATE_KOMENTAR));
isi_komentar.setText(tulisan.get(ContentCommentActivity.TAG_ISI_KOMENTAR));
nama_komentar.setText(tulisan.get(ContentCommentActivity.TAG_NAMA_KOMENTAR));
id_tulisan_komentar.setText(tulisan.get(ContentCommentActivity.TAG_ID_TULISAN_KOMENTAR));
String avatar_komentar = tulisan.get(ContentCommentActivity.TAG_AVATAR_KOMENTAR);
if(hide_gambar.equals("Y")){
thumb_image.setVisibility(View.GONE);
}
else{
thumb_image.setVisibility(View.GONE);
/* thumb_image.setVisibility(View.VISIBLE);
if (avatar_komentar.equals("")) {
thumb_image.setVisibility(View.GONE);
} else {
imageLoader.DisplayImage(tulisan.get(ContentCommentActivity.TAG_AVATAR_KOMENTAR), thumb_image);
thumb_image.setVisibility(View.VISIBLE);
} */
}
activity.registerForContextMenu(act_komentar);
act_komentar.setOnClickListener(new android.view.View.OnClickListener()
{
public void onClick(View v)
{
activity.openContextMenu(v);
v.showContextMenu();
}
});
return vi;
}
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
menu.setHeaderTitle("My Context Menu");
menu.add(0, 1, 0, "Add");
menu.add(0, 2, 0, "Edit");
menu.add(0, 3, 1, "Delete");
}
你能告诉我,它应该如何工作?