我有一些問題android textview value
我想更改我的textview值。當我的代碼變化將改變
這裏是代碼
public class SubMenuActivity extends Activity {
private static final int GALLERY = 0;
private static final int SUBMANU01 = 7;
private static final int MANU01 = 1;
private static final int MANU02 = 2;
private static final int MANU03 = 3;
private static final int MANU04 = 4;
private static final int MANU05 = 5;
TextView tx1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tx1 =(TextView)this.findViewById(R.id.textView1);
if(tx1.toString()=="1".toString())
{
tx1.setText("7");
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
SubMenu fileMenu = menu.addSubMenu(GALLERY, SUBMANU01, Menu.NONE, "File");
fileMenu.add(GALLERY, MANU01, Menu.NONE, "new");
fileMenu.add(GALLERY, MANU02, Menu.NONE, "open");
fileMenu.add(GALLERY, MANU03, Menu.NONE, "save");
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MANU01:
case MANU02:
case MANU03:
final String itemid = Integer.toString(item.getItemId());
tx1.setText(itemid);
return true;
}
return super.onOptionsItemSelected(item);
}
tx1.text值並沒有表現出7,問題出在哪裏? 我希望有人能告訴我這個問題。
使用'equals',而不是''==,後者比較引用這是'tx1.toString'之間不同的' 「1」' – Aprian
什麼在TX1的TextView所示。? –