I\'m using the support NavigationView in my navigation drawer to display menu of items.
I can change the text of the counter easily enough. However, The text view that I use is within a LinearLayout
, and it has an android:id as well (I tried this without the LinearLayout
without issue):
Given that, I am able to see, access and modify the text view within the main activity using the following :
TextView countText = (TextView)findViewById(R.id.textCounter);
countText.setText("6");
Of course, I'm using a trivial method to calculate the value, just setting it to the value "6", but, I don't know what your counter structure actually looks like, and those are not the main concern of your question.
The issue with your ability to view the counter number remains a mystery. See my questions above and we'll hammer out that element as well.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}