我有问题

我想更改我的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,问题出在哪里?
我希望有人能告诉我这个问题。

最佳答案

像这样比较

 if(tx1.getText().toString().equals("1"))
 {
   tx1.setText("7");
 }

07-24 12:28