我正在构建原生Android应用程序。 我有一个菜单,我想显示和隐藏项目,具体取决于登录的人(孩子或父母)。
我在共享偏好设置中保存此人的登录信息。这工作正常。我得到了登录人员的信息。
问题是菜单,它只在某个时候有效。
我是初学者,我们将不胜感激。
public class BaseActivity extends AppCompatActivity {
String auth_user, toolbox_access, results_access;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences preferences = getSharedPreferences("PREF", MODE_PRIVATE);
auth_user = (preferences.getString("auth_settings", ""));
toolbox_access = (preferences.getString("toolbox_access", ""));
results_access = (preferences.getString("results_access", ""));
}
public void Toolbar(){
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Drawable drawable = ContextCompat.getDrawable(getApplicationContext(),R.drawable.ic_reorder_black_24dp);
toolbar.setOverflowIcon(drawable);
//Toolbar title
TextView toolbar_title = (TextView)findViewById(R.id.toolbar_title);
toolbar_title.setText(getString(R.string.action_exercise));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
if(auth_user == "Parent"){
MenuItem item = menu.findItem(R.id.action_card_list);
item.setVisible(false);
}
if(auth_user == "Child"){
MenuItem item = menu.findItem(R.id.action_card_list);
item.setVisible(true);
}
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
if (id == R.id.action_login) {
startActivity(new Intent(this, LoginActivity.class));
}
if (id == R.id.action_exercise) {
startActivity(new Intent(this, ExerciseListActivity.class));
}
if (id == R.id.action_top_problems) {
startActivity(new Intent(this, ExercisePostActivity.class));
}
if (id == R.id.action_test) {
startActivity(new Intent(this, TestActivity.class));
}
if (id == R.id.action_exercise2) {
startActivity(new Intent(this, AssessmentDailyActivity.class));
}
if (id == R.id.action_ocdlist) {
startActivity(new Intent(this, OcdListActivity.class));
}
if (id == R.id.action_card_list) {
startActivity(new Intent(this, CardActivity.class));
}
if (id == R.id.action_results) {
startActivity(new Intent(this, ResultsActivity.class));
}
return super.onOptionsItemSelected(item);
}
}
答案 0 :(得分:1)
使用var date = document.getElementById("table").children[0].children[1].innerHTML;
var new_date = 06/12/2016;
if (date < new_date) ...
比较字符串是否相等。
.equals()