模拟器显示加载

时间:2016-06-14 13:20:09

标签: android xml emulation

我在MainActivityListFragment中的代码声明从未使用方法OnActivityCreated(android.os.Bundle)'结果是灰色的。我也无法在它之前添加@Override。当我运行应用程序时,它会继续加载而不是显示列表。我非常感谢你的帮助,因为我正在为一个项目做这件事:)

content_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.enxin.crystallise.MainActivity"
tools:showIn="@layout/activity_main">

<fragment
    android:id="@+id/mainActivityFrag"
    android:name="com.example.enxin.crystallise.MainActivityListFragment"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    tools:layout="@android:layout/simple_list_item_1" />
</LinearLayout>

MainActivityListFragment

package com.example.enxin.crystallise;

import android.app.ListFragment;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

/**
 * Created by En Xin on 11/6/2016.
 */
public class MainActivityListFragment extends ListFragment {


public void OnActivityCreated(Bundle savedInstanceState){
    super.onActivityCreated(savedInstanceState);

    String[] values = new String[]{ "Android","iPhone", "WindowsMobile", "Blackberry", "WebOS",
            "Ubuntu","Windows7", "Linux"};

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
            android.R.layout.simple_list_item_1, values);

    setListAdapter(adapter);

}

@Override
public void onListItemClick(ListView l, View v, int position, long id){
    super.onListItemClick(l,v,position,id);
}
}

1 个答案:

答案 0 :(得分:0)

您的OnActivityCreated应以小写o开头。将OnActivityCreated更改为onActivityCreated,然后添加@Override:

@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// the rest of your method