I am a total novice at java/android and I just cant figure out whats going wrong or what I have to do in order to get pictures to draw to screen when I click the buttons I have set up. Ive tried replacing the classes but that does no good because I dont know how to use the methods or functions to get stuff to work right.....Ill just post all the code I have so you guys can see the mess I have so far.....can some one please help because I have 30 java books and 10 android books that Ive been skimming through and I even have looked over the android developers page but it doesnt help at all.....I feel like Im trying to read chinese or something.
Heres my main java file:
package test.button;
import android.app.Activity;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class button extends Activity {
/** Called when the activity is first created. */
Button myButton;
EditText myText;
protected int count;
int i = 0;
long pictures[] = {R.drawable.hot_girls, R.drawable.hillarious_post, };
int numGirls = 2;
@Override
LinearLayout mLinearLayout;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Create a LinearLayout in which to add the ImageView
mLinearLayout = new LinearLayout(this);
// Instantiate an ImageView and define its properties
ImageView i = new ImageView(this);
i.setImageResource(R.drawable.icon);
i.setAdjustViewBounds(true); // set the ImageView bounds to match the Drawable's dimensions
i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
// Add the ImageView to the layout and set the layout as the content view
mLinearLayout.addView(i);
setContentView(mLinearLayout);
}
//public void onCreate(Bundle savedInstanceState) {
//super.onCreate(savedInstanceState);
//getWindow().setBackgroundDrawableResource(R.drawable.icon) ;
myButton = (Button) findViewById (R.id.my_button);
myText = (EditText) findViewById (R.id.my_text);
myText.setSingleLine();
myText.setInputType(InputType.TYPE_NULL);
myButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
myText.setText("youve touched the screen"+ ++count +" times");
if (i < (numGirls - 1))
{
i++;
getWindow().setBackgroundDrawableResource((int) pictures) ;
}
else
{
i = 0;
getWindow().setBackgroundDrawableResource((int) pictures) ;
}
}
});
}
}
and now heres what I have in the main xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
androidrientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
androidadding="4px">
<EditText
android:id="@+id/my_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</EditText>
<Button android:text="@string/button_text"
android:id="@+id/my_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
some one help me fix this its been driving me crazy for 2 months or so now.
Heres my main java file:
package test.button;
import android.app.Activity;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class button extends Activity {
/** Called when the activity is first created. */
Button myButton;
EditText myText;
protected int count;
int i = 0;
long pictures[] = {R.drawable.hot_girls, R.drawable.hillarious_post, };
int numGirls = 2;
@Override
LinearLayout mLinearLayout;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Create a LinearLayout in which to add the ImageView
mLinearLayout = new LinearLayout(this);
// Instantiate an ImageView and define its properties
ImageView i = new ImageView(this);
i.setImageResource(R.drawable.icon);
i.setAdjustViewBounds(true); // set the ImageView bounds to match the Drawable's dimensions
i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
// Add the ImageView to the layout and set the layout as the content view
mLinearLayout.addView(i);
setContentView(mLinearLayout);
}
//public void onCreate(Bundle savedInstanceState) {
//super.onCreate(savedInstanceState);
//getWindow().setBackgroundDrawableResource(R.drawable.icon) ;
myButton = (Button) findViewById (R.id.my_button);
myText = (EditText) findViewById (R.id.my_text);
myText.setSingleLine();
myText.setInputType(InputType.TYPE_NULL);
myButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
myText.setText("youve touched the screen"+ ++count +" times");
if (i < (numGirls - 1))
{
i++;
getWindow().setBackgroundDrawableResource((int) pictures) ;
}
else
{
i = 0;
getWindow().setBackgroundDrawableResource((int) pictures) ;
}
}
});
}
}
and now heres what I have in the main xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
androidrientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
androidadding="4px">
<EditText
android:id="@+id/my_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</EditText>
<Button android:text="@string/button_text"
android:id="@+id/my_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
some one help me fix this its been driving me crazy for 2 months or so now.