我在Ubuntu上使用Android Studio运行一个简单的应用程序。它运行但屏幕是空白的

时间:2015-02-14 06:28:24

标签: android ubuntu android-studio

MainActivity.java

package com.example.desperado.sunshine;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment())
                    .commit();
        }
    }


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

        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {

            String[] data = {
                    "Mon 6/23 - Sunny - 31/17",
                    "Tue 6/24 - Foggy - 21/8",
                    "Wed 6/25 - Cloudy - 22/17",
                    "Thurs 6/26 - Rainy - 18/11",
                    "Fri 6/27 - Foggy - 21/10",
                    "Sat 6/28 - TRAPPED IN WEATHERSTATION - 23/18",
                    "Sun 6/29 - Sunny - 20/7"
            };
            List<String> weekForecast = new ArrayList<String>(Arrays.asList(data));


            View rootView = inflater.inflate(R.layout.fragment_main, container, false);
            return rootView;
        }
    }
}

fragment_main.xml

<FrameLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.example.android.sunshine.app.MainActivity$PlaceholderFragment">
    <ListView
        android:id="@+id/listview_forecast"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</FrameLayout>

list_item_forecast.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:gravity="center_vertical"
    android:id="@+id/list_item_forecast_textview" />

logcat的

>02-14 00:55:05.840    1814-1814/com.example.desperado.sunshine    D/dalvikvm﹕ Not late-enabling CheckJNI (already on) 

>02-14    00:55:05.890    1814-1814/com.example.desperado.sunshine I/dalvikvm﹕    Could not find method android.view.ViewGroup.onNestedScrollAccepted,    referenced from method    android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted    

>02-14 00:55:05.890    1814-1814/com.example.desperado.sunshine    W/dalvikvm﹕ VFY: unable to resolve virtual method 11345:    Landroid/view/ViewGroup;.onNestedScrollAccepted    (Landroid/view/View;Landroid/view/View;I)V 

>02-14 00:55:05.890       1814-1814/com.example.desperado.sunshine D/dalvikvm﹕ VFY: replacing    opcode 0x6f at 0x0000 

>02-14 00:55:05.890       1814-1814/com.example.desperado.sunshine I/dalvikvm﹕ Could not find    method android.view.ViewGroup.onStopNestedScroll, referenced from    method    android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll    
>02-14 00:55:05.890    1814-1814/com.example.desperado.sunshine    W/dalvikvm﹕ VFY: unable to resolve virtual method 11351:    Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V    

>02-14 00:55:05.890    1814-1814/com.example.desperado.sunshine    D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000 

>02-14 00:55:05.890      1814-1814/com.example.desperado.sunshine I/dalvikvm﹕ Could not find    method    android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll,    referenced from method    android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled    

>02-14 00:55:05.890    1814-1814/com.example.desperado.sunshine    W/dalvikvm﹕ VFY: unable to resolve virtual method 9039:    Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll    ()V 

>02-14 00:55:05.900    1814-1814/com.example.desperado.sunshine    D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e 

>02-14 00:55:05.900      1814-1814/com.example.desperado.sunshine I/dalvikvm﹕ Could not find    method android.content.res.TypedArray.getChangingConfigurations,    referenced from method    android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations    
>02-14 00:55:05.900    1814-1814/com.example.desperado.sunshine    W/dalvikvm﹕ VFY: unable to resolve virtual method 364:    Landroid/content/res/TypedArray;.getChangingConfigurations ()I 

>02-14    00:55:05.900    1814-1814/com.example.desperado.sunshine D/dalvikvm﹕    VFY: replacing opcode 0x6e at 0x0002 

>02-14 00:55:05.900       1814-1814/com.example.desperado.sunshine I/dalvikvm﹕ Could not find    method android.content.res.TypedArray.getType, referenced from method    android.support.v7.internal.widget.TintTypedArray.getType 

>02-14    00:55:05.900    1814-1814/com.example.desperado.sunshine W/dalvikvm﹕    VFY: unable to resolve virtual method 386:    Landroid/content/res/TypedArray;.getType (I)I 

>02-14 00:55:05.900       1814-1814/com.example.desperado.sunshine D/dalvikvm﹕ VFY: replacing    opcode 0x6e at 0x0002 

>02-14 00:55:05.910       1814-1814/com.example.desperado.sunshine D/dalvikvm﹕ GC_FOR_ALLOC    freed 147K, 8% free 3069K/3324K, paused 3ms, total 4ms 

>02-14    00:55:05.910    1814-1814/com.example.desperado.sunshine    I/dalvikvm-heap﹕ Grow heap (frag case) to 4.173MB for 1127532-byte    allocation 

>02-14 00:55:05.930       1814-1823/com.example.desperado.sunshine D/dalvikvm﹕ GC_FOR_ALLOC    freed 13K, 7% free 4157K/4428K, paused 19ms, total 19ms 

>02-14    00:55:05.980    1814-1814/com.example.desperado.sunshine D/﹕    HostConnection::get() New Host Connection established 0xb7dcf7d0, tid    1814 

>02-14 00:55:06.000    1814-1814/com.example.desperado.sunshine    W/EGL_emulation﹕ eglSurfaceAttrib not implemented 

>02-14 00:55:06.000     1814-1814/com.example.desperado.sunshine D/OpenGLRenderer﹕ Enabling    debug mode 0

1 个答案:

答案 0 :(得分:0)

当然是空的,你显示一个没有任何物品的空ListView。你能指望什么 ?您必须将适配器传递给ListView并做一些工作以查看listView,请完成此http://www.vogella.com/tutorials/AndroidListView/article.html