问题描述
- android程序运行后长按不弹出菜单,找不到原因。
-
public class Chan_List extends ListActivity {private ScanActivity sActivity = null; private static final String TAG = "RCU"; private SimpleAdapter listAdapter = null; private MobileControl mControl=null; private ListView show; private List<Map<String, Object>>chanlist=new ArrayList<Map<String, Object>>(); Map<String, Object> map; public Chan_List() { // TODO Auto-generated constructor stub } @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); mControl = (MobileControl) getApplicationContext(); setContentView(R.layout.chan_list); map=new HashMap<String, Object>(); map.put("chan_index", "1."); map.put("chan_name", "CCTV10"); chanlist.add(map); listAdapter = new SimpleAdapter(Chan_List.this, chanlist, R.layout.chanlist, new String[] { "chan_index", "chan_name" }, new int[] { R.id.chan_index, R.id.chan_name }); setListAdapter(listAdapter);
show= new ListView(this);
registerForContextMenu(show);}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
// TODO Auto-generated method stub
super.onCreateContextMenu(menu, v, menuInfo);
menu.add(0,0,0,"sort");
menu.add(0,1,0,"delate");
menu.add(0,2,0,"move");}
@Override
public boolean onContextItemSelected(MenuItem item){
AdapterView.AdapterContextMenuInfo info =(AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
switch (item.getItemId()) {
case 0:
Toast.makeText(Chan_List.this, "he", Toast.LENGTH_SHORT).show();
break;default: break; } return super.onContextItemSelected(item);
}
}
解决方案
长按的响应函数有错。
解决方案二:
你要给listView设置长按时间,show.setOnItemLongClickListener(new onItemLongClickListener(){//长按触发的事件})
解决方案三:
已经解决,果断是show=ListView(this)这样不行