This is My XML followed by the only class I have I need to know why when I press the button if it has a background set I get no read out in the console. I have no idea what I am doing wrong it says it can find the method it knows the method the method has (View view) in it. I have searched for hours trying to make it "clickable" even explicitly stated the visibility and android:clickable="true" hopefully a "pro" someone thats not in high school as my self can explain this.
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/tableView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="*"
android:weightSum="3" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:weightSum="4" >
<ImageButton
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:soundEffectsEnabled="false"
android:gravity="center"
android:textSize="0dp"
android:id="@+id/Card1"
android:src="@drawable/card0000"
android:background="@drawable/unselected"
android:scaleType="fitCenter"
android:onClick="cardSelect"
android:clickable="true"
android:visibility="visible" />
<ImageButton
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:soundEffectsEnabled="false"
android:gravity="center"
android:textSize="0dp"
android:id="@+id/Card2"
android:src="@drawable/card0000"
android:background="@drawable/unselected"
android:scaleType="fitCenter"
android:onClick="cardSelect"
android:clickable="true"
android:visibility="visible" />
<ImageButton
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:soundEffectsEnabled="false"
android:gravity="center"
android:textSize="0dp"
android:id="@+id/Card3"
android:src="@drawable/card0000"
android:background="@drawable/unselected"
android:scaleType="fitCenter"
android:onClick="cardSelect"
android:clickable="true"
android:visibility="visible" />
<ImageButton
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:soundEffectsEnabled="false"
android:gravity="center"
android:textSize="0dp"
android:id="@+id/Card4"
android:src="@drawable/card0000"
android:background="@drawable/unselected"
android:scaleType="fitCenter"
android:onClick="cardSelect"
android:clickable="true"
android:visibility="visible" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:weightSum="4"
android:src="@drawable/card0000">
<ImageButton
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:soundEffectsEnabled="false"
android:gravity="center"
android:textSize="0dp"
android:id="@+id/Card5"
android:src="@drawable/card0000"
android:background="@drawable/unselected"
android:scaleType="fitCenter"
android:onClick="cardSelect"
android:clickable="true"
android:visibility="visible" />
<ImageButton
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:soundEffectsEnabled="false"
android:gravity="center"
android:textSize="0dp"
android:id="@+id/Card6"
android:src="@drawable/card0000"
android:background="@drawable/unselected"
android:scaleType="fitCenter"
android:onClick="cardSelect"
android:clickable="true"
android:visibility="visible" />
<ImageButton
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:soundEffectsEnabled="false"
android:gravity="center"
android:textSize="0dp"
android:id="@+id/Card7"
android:src="@drawable/card0000"
android:background="@drawable/unselected"
android:scaleType="fitCenter"
android:onClick="cardSelect"
android:clickable="true"
android:visibility="visible" />
<ImageButton
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:soundEffectsEnabled="false"
android:gravity="center"
android:textSize="0dp"
android:id="@+id/Card8"
android:src="@drawable/card0000"
android:background="@drawable/unselected"
android:scaleType="fitCenter"
android:onClick="cardSelect"
android:clickable="true"
android:visibility="visible" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:weightSum="4"
android:src="@drawable/card0000">
<ImageButton
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:soundEffectsEnabled="false"
android:gravity="center"
android:textSize="0dp"
android:id="@+id/Card9"
android:src="@drawable/card0000"
android:background="@drawable/unselected"
android:scaleType="fitCenter"
android:onClick="cardSelect"
android:clickable="true"
android:visibility="visible" />
<ImageButton
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:soundEffectsEnabled="false"
android:gravity="center"
android:textSize="0dp"
android:id="@+id/Card10"
android:src="@drawable/card0000"
android:background="@drawable/unselected"
android:scaleType="fitCenter"
android:onClick="cardSelect"
android:clickable="true"
android:visibility="visible" />
<ImageButton
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:soundEffectsEnabled="false"
android:gravity="center"
android:textSize="0dp"
android:id="@+id/Card11"
android:src="@drawable/card0000"
android:background="@drawable/unselected"
android:scaleType="fitCenter"
android:onClick="cardSelect"
android:clickable="true"
android:visibility="visible" />
<ImageButton
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:soundEffectsEnabled="false"
android:gravity="center"
android:textSize="0dp"
android:id="@+id/Card12"
android:src="@drawable/card0000"
android:background="@drawable/unselected"
android:scaleType="fitCenter"
android:onClick="cardSelect"
android:clickable="true"
android:visibility="visible" />
</TableRow>
</TableLayout>
The main Class the only one thats in use at this case all my other classes aren't declared here and don't need to be.
package skyguy913.myapplication;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
public class MainActivity extends Activity {
//public EditText textField;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//TODO add code to initiate application
setTitle("My new title");
//textField = (EditText) findViewById(R.id.editText);
}
@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_main, 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
/* TODO add code to respond to reset
if (id == R.id.action_settings) {
return true;
}
*/
return super.onOptionsItemSelected(item);
}
public void cardSelect(View view) {
/*
Drawable buttonBackground = view.getBackground();
Drawable unselected = getResources().getDrawable( R.drawable.unselected);
Drawable selected = getResources().getDrawable( R.drawable.selected);
if(buttonBackground == unselected){
view.setBackground(selected);
} else {
view.setBackground(unselected);
}
*/
System.out.print("Click");
//TODO add code to respond to card select
}
}
0 comments:
Post a Comment