我有一个ListView
应用,在应用中我想要不同的项目点击监听器。卡片视图showld显示所选项目名称的祝酒词,并且在点击图像按钮时,它应该打开特定项目的上下文菜单。
我的适配器
class AdapterForList extends BaseAdapter {
public AdapterForList(Activity activity, ArrayList<ProviderVideoDetails> singletons) {
}
convertView = this.inflater.inflate(R.layout.XML_list_row, null);
final ImageButton I = (ImageButton) convertView.findViewById(R.id.image);
final CardView C = (CardView) convertView.findViewById(R.id.card);
C.setOnClickListener(new android.view.View.OnClickListener() {
@Override
public void onClick(View v) {
// should show a toast of selected item name
}
});
I.setOnClickListener(new android.view.View.OnClickListener() {
@Override
public void onClick(View v) {
// should open context menu of selected item
}
});*/
}
在XML_list_row中
<android.support.v7.widget.CardView
android:id="@+id/card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardElevation="3dp"
app:cardCornerRadius="3dp">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content
app:srcCompat="@drawable/image" />
</RelativeLayout>
</android.support.v7.widget.CardView>
在活动我的上下文菜单
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
if (v.getId() == R.id.listVideos) {
menu.add(0,0,0,"Op1");
menu.add(0,1,1,"Op2");
}
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
switch (item.getItemId()) {
请帮帮我,谢谢。