简体   繁体   中英

main activity not loading android

i have designed my mainActivity, but for some reason none of my elements are showing up (i am quite new to android development)

here is my home screen.java:

public class HomeScreen extends ActionBarActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.home_screen, 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();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

my logCat:

09-11 13:45:42.359    1935-1935/au.gov.nsw.shellharbour.saferroadsshellharbour E/dalvikvm﹕ could not disable core file generation for pid 1935: Operation not permitted
09-11 13:45:43.460    1935-1935/au.gov.nsw.shellharbour.saferroadsshellharbour D/dalvikvm﹕ GC_EXTERNAL_ALLOC freed 114K, 47% free 2782K/5191K, external 2441K/2773K, paused 119ms
09-11 13:45:43.585    1935-1935/au.gov.nsw.shellharbour.saferroadsshellharbour D/dalvikvm﹕ GC_EXTERNAL_ALLOC freed 4K, 47% free 2783K/5191K, external 3178K/3481K, paused 93ms
09-11 13:45:43.742    1935-1935/au.gov.nsw.shellharbour.saferroadsshellharbour D/dalvikvm﹕ GC_EXTERNAL_ALLOC freed <1K, 47% free 2785K/5191K, external 3618K/4030K, paused 118ms
09-11 13:45:44.031    1935-1935/au.gov.nsw.shellharbour.saferroadsshellharbour D/dalvikvm﹕ GC_EXTERNAL_ALLOC freed <1K, 47% free 2789K/5191K, external 4497K/4579K, paused 129ms
09-11 15:18:36.725    1935-1935/au.gov.nsw.shellharbour.saferroadsshellharbour D/dalvikvm﹕ GC_EXPLICIT freed 421K, 50% free 2869K/5639K, external 4545K/5676K, paused 99ms

there is no functionality built in as of yet - i just want to ge the layout right, which is given below:

    <LinearLayout 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:orientation="vertical"
    tools:context=".HomeScreen">

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="40dp"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/TextView01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="5dp"
            android:text="Latitude: "
            android:textSize="20dip"/>

        <TextView
            android:id="@+id/TextView02"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="unknown"
            android:textSize="20dip"/>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/TextView03"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dip"
            android:layout_marginRight="5dip"
            android:text="Longitude"
            android:textSize="20dip"/>

        <TextView
            android:id="@+id/TextView04"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="unkown"
            android:textSize="20dip"/>


    </LinearLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="259dp"
        android:id="@+id/scrollView"
        android:layout_gravity="center_vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:orientation="vertical">

            <ImageButton
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:id="@+id/btn_dob_in_a_hoon"
                android:layout_gravity="center_horizontal"
                android:clickable="true"
                android:src="@drawable/dobinahoonmenu"/>
            <ImageButton
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:id="@+id/btn_report_a_hazard"
                android:layout_gravity="center_horizontal"
                android:clickable="true"
                android:src="@drawable/reportahazardmenu"/>
            <ImageButton
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:id="@+id/btn_Old_logo"
                android:layout_gravity="center_horizontal"
                android:clickable="true"
                android:src="@drawable/oldlogomenu"/>
            <ImageButton
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:id="@+id/btn_Council_Website"
                android:layout_gravity="center_horizontal"
                android:clickable="true"
                android:src="@drawable/councilwebsitemenu"/>

        </LinearLayout>
    </ScrollView>



    <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/horizontalScrollView2" >
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="51dp"
            android:layout_gravity="center_horizontal|bottom">


            <ImageButton
                android:layout_width="60dp"
                android:layout_height="match_parent"
                android:id="@+id/facebook"
                android:layout_gravity="center_horizontal"
                android:clickable="true"
                android:src="@drawable/facebookbutton"
                android:scaleType="fitCenter"/>

            <ImageButton
                android:layout_width="60dp"
                android:layout_height="match_parent"
                android:id="@+id/twitter"
                android:layout_gravity="center_horizontal"
                android:clickable="true"
                android:src="@drawable/scclogoold"
                android:scaleType="fitCenter"/>

            <ImageButton
                android:layout_width="60dp"
                android:layout_height="match_parent"
                android:id="@+id/contact"
                android:layout_gravity="center_horizontal"
                android:clickable="true"
                android:src="@drawable/contactbutton"
                android:scaleType="fitCenter"/>

        </LinearLayout>


    </HorizontalScrollView>


</LinearLayout>

any help would be greatly appreciated.

you must inflate your Layout!!!

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.your_layout_name);  //i don't know the xml-filename!
}

When you create activity, it will setContentView automatically. I don't know why you have no this codes.

You created the activity, but did not mention which layout should be displayed or associated with the Homescreen class. For that add

setContentView(R.layout.your_homescreen_layout_name);

Brother, Put the home screen xml files name instead of your_homescreen_layout_name Happy coding.. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM