所以我在android上的菜单中查找标题时出现问题。我试图做的是创建一个“if”,它将获得文本“Home”并将其更改为“asdas”但由于某种原因它不会进入“if”。我认为它很容易解决,但我必须遗漏一些东西。
感谢所有
if(menu.getHeaderType() == HeaderType.HeaderType_CATEGORY) {
frameCategory.setVisibility(View.VISIBLE);
Spanned title = Html.fromHtml(MainActivity.this.getResources().getString(menu.getMenuResTitle()));
TextView tvTitle = (TextView) v.findViewById(R.id.tvTitle);
//This is the if that should change home to asdas
if (tvTitle.getText() == "Home"){
tvTitle.setText("asdas");
Log.v("myApp", "ASDA - ASDA - ASDA - ASDA - ASDA - ASDA - ASDA - ASDA - ASDA - ASDA - ASDA - ASDA - ASDA" );
}else {
tvTitle.setText(title);
}
ImageView imgViewIcon = (ImageView) v.findViewById(R.id.imgViewIcon);
imgViewIcon.setImageResource(menu.getMenuResIconSelected());
}
答案 0 :(得分:0)
这是错误的地方:
if (tvTitle.getText() == "HOME")
//----------^^^^^^^^^------------
{
tvTitle.setText("asdas");
Log.v("myApp", "ASDA - ASDA - ASDA - ASDA - ASDA - ASDA - ASDA - ASDA - ASDA - ASDA - ASDA - ASDA - ASDA" );
}
这是应该:
的方式if (tvTitle.getText().toString() == "HOME")
//-------------------^^^^^^^^^^^-----------
{
tvTitle.setText("asdas");
Log.v("myApp", "ASDA - ASDA - ASDA - ASDA - ASDA - ASDA - ASDA - ASDA - ASDA - ASDA - ASDA - ASDA - ASDA" );
}