I know there are a couple of questions similar to this but I've tried different things suggested such as cleaning and rebuilding and still nothing is working for me. I'm new to android and working on Eclipse. I'm trying to make a simple test app where a user clicks an image button (a ball) and there is a textview which changes text when the button is clicked.
As I'm new to android, I've noticed there is a fragment main.xml and a main.xml so I'm wondering if there is meant to be 2.
Does anyone know why this isn't running on emulator or device? Thanks for any help.
main -
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>
</menu>
fragment main -
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.imagebutton.MainActivity$PlaceholderFragment" >
<ImageButton
android:id="@+id/ball"
android:layout_width="100dip"
android:layout_height="100dip"
android:scaleType="fitXY"
android:src="@drawable/ball"
/>
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/ball"
android:layout_marginBottom="36dp"
android:layout_marginLeft="48dp"
android:layout_toRightOf="@+id/ball"
android:text="@string/click" />
</RelativeLayout>
Main Activity - package com.example.imagebutton;
import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
import android.os.Build;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageButton ballButton = (ImageButton) findViewById(R.id.ball);
ballButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick (View v){
TextView text = (TextView) findViewById(R.id.tv);
text.setText("It has been clicked!");
}
});
}
}
Manifest -
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.imagebutton.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>