Example #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);
  }