Good Day
I want to try some stuff with Android Studio (im oretty new in java) So what I want to do is a Tic-Tac-Toe. I have created a button and want to assign this button a function.
public class TicTacToe extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tic_tac_toe);
/*Button i created*/
Button btn1 = (Button)findViewById(R.id.button1);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_tic_tac_toe, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void onClick(View view){
btn1 /*is not recognized. and here i want the button to do something. but its
not possible. Where is the mistake?*/
}
}
Here the xml
<TextView
android:layout_width="60dp"
android:layout_height="60dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/text1"
android:onClick="changeText"
android:layout_alignBottom="@+id/button1"
android:layout_toLeftOf="@+id/button2"
android:layout_alignLeft="@+id/button1"
android:layout_alignStart="@+id/button1"
android:layout_alignTop="@+id/button1" />
Do you guys have any idea? Am I doing errors in reasoning? Thanks in advance FIISHxMAN
0 comments:
Post a Comment