コード例 #1
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == android.R.id.home) {
      finish();
    }
    if (id == R.id.save) {
      boolean flag = DataUtils.isExist(topic.id);
      if (flag) {
        DataUtils.delete(topic.id);
        item.setTitle("收藏");
      } else {
        DataUtils.storeItem(topic);
        item.setTitle("取消收藏");
      }
    }
    if (id == R.id.openByBroswer) {
      Intent i = new Intent(this, WebViewActivity.class);
      i.putExtra("url", topic.url);
      i.putExtra("title", "详情");
      startActivity(i);
    }

    return super.onOptionsItemSelected(item);
  }
コード例 #2
0
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
   // Inflate the menu; this adds items to the action bar if it is present.
   getMenuInflater().inflate(R.menu.menu_main, menu);
   boolean flag = DataUtils.isExist(topic.id);
   if (flag) {
     menu.getItem(0).setTitle("取消收藏");
   } else {
     menu.getItem(0).setTitle("收藏");
   }
   return true;
 }