用工具栏方式代替列表视图

时间:2018-10-06 04:17:16

标签: java android

lvRSS = (ListView)findViewById (R.id.lvRSS)
lvRSS.setOnItemClickListener (new AdapterView.OnItemClickListener(){
  public void onItemClick (AdpaterView<?>parent,View view, int position, 
  long id)
}

它将在listview上工作,但我无法模仿工具栏上的

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setOnItemClickListener (new AdapterView.OnItemClickListener(){
      public void onItemClick (AdpaterView<?>parent,View view, int 
      position, long id)
    }

请帮助

1 个答案:

答案 0 :(得分:1)

工具栏不包含setOnItemClickListener()事件。如果要使事件单击工具栏,请尝试以下操作:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });