I am making my TextView clickable and want the text to change as I click on it. So the TextView starts out saying "Al" and when its clicked I want it to change to say, let just say "Hi" for now. And then also go back when clicked again. Here is my code.
package table.periodic;
import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.ContextMenu; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.TextView;
public class Aluminum extends Activity{ public Button next; public TextView symbol; public static final int ONE_ID = Menu.FIRST+1; public static final int TWO_ID = Menu.FIRST+2; public static final int THREE_ID = Menu.FIRST+3; public static final int FOUR_ID = Menu.FIRST+4; public static final int FIVE_ID = Menu.FIRST+5; public static final int SIX_ID = Menu.FIRST+6;
public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.aluminum); symbol = (TextView) findViewById(R.id.symbol);
symbol.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { symbol = (TextView) findViewById(R.id.symbol); if ("Al".equals(symbol.getText())); symbol.setText("Hi"); if ("Hi".equals(symbol.getText())); symbol.setText("Al");} }); next = (Button) findViewById(R.id.next); next.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent next = new Intent(Aluminum.this,
Aluminum2.class); startActivity(next);}});
} public void onCreateContextMenu(ContextMenu menu,
View v, ContextMenu.ContextMenuInfo menuInfo){ populateMenu(menu); }
public boolean onCreateOptionsMenu(Menu menu){ populateMenu(menu); return(super.onCreateOptionsMenu(menu)); } public boolean onOptionsItemSelected(MenuItem item){ return(applyMenuChoice(item)|| super.onOptionsItemSelected(item)); } public boolean onContextItemSelected(MenuItem item){ return(applyMenuChoice(item)|| super.onContextItemSelected(item)); } private void populateMenu(Menu menu){ menu.add(Menu.NONE, ONE_ID, Menu.NONE, "Help"); menu.add(Menu.NONE, TWO_ID, Menu.NONE, "Home"); menu.add(Menu.NONE, THREE_ID, Menu.NONE, "List"); menu.add(Menu.NONE, FOUR_ID, Menu.NONE, "Table"); } private boolean applyMenuChoice(MenuItem item){ switch (item.getItemId()){ case ONE_ID: Intent help = new Intent(this, Help.class); startActivity(help); return(true); case TWO_ID: Intent table = new Intent(this, table.class); startActivity(table); return(true); case THREE_ID: Intent list = new Intent(this, List.class); startActivity(list); return(true); case FOUR_ID: Intent Classic = new Intent(this, Classic.class); startActivity(Classic); return(true); } return false; } }