0
我在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);
}
}
謝謝soooooo多:) –