我正在显示消息列表,使用显示来自 Adaptar 的 ListView 的 Activity,如下所示。
我需要在下面的DiscussArrayAdapter
类中的 ImageView 中注册 ContextMenu 菜单。
如果我只是registerForContextMenu(arrowImage);
从DiscussArrayAdapter
它打电话不会接受它。
另外,我不知道在哪里覆盖该方法onCreateContextMenu
我的 messageActivity 如下:
public class MessagesActivity extends Activity {
private ListView listView = null;
/** Called when the activity is first created. */
private DiscussArrayAdapter adapter;
private ListView lv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_discuss);
registerReceiver(mHandleMessageReceiver, new IntentFilter(
DISPLAY_MESSAGE_ACTION));
adapter = new DiscussArrayAdapter(getApplicationContext(), R.layout.listitem_discuss);
lv.setAdapter(adapter);
我有DiscussArrayAdapter
课:
public class DiscussArrayAdapter extends ArrayAdapter<OneMessage>{
private /*TextView*/EditText msgTextView;
private TextView sender;
private LinearLayout wrapper;
private SqlHelper dbHelper = null;
private Context context;
@Override
public void add(OneMessage object) {
dbHelper.addNewMessage(object);
super.add(object);
}
public DiscussArrayAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
this.context=context;
if (dbHelper == null) {
dbHelper = new SqlHelper(context);
}
}
public int getCount() {
return dbHelper.getContactsCount();
}
public OneMessage getItem(int index) {
return dbHelper.getOneComment(index+dbHelper.lastRawID());
}
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
if (row == null) {
LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.listitem_discuss, parent, false);
}
wrapper = (LinearLayout) row.findViewById(R.id.wrapper);
ImageView arrowImage = (ImageView) row.findViewById(R.id.aquaplayicon);
// this .registerForContextMenu(arrowImage);
OneMessage coment = getItem(position);
msgTextView =/*(TextView)*/(EditText) row.findViewById(R.id.comment);
为简洁起见,我省略了其余代码。