English 中文(简体)
安乐施会
原标题:Android ListFragment is to confusing

I m 如此混淆使用清单...... 我无法理解问题何在。

这里是我的分裂主义行为类别:

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

public class menu extends FragmentActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
            setContentView(R.layout.root_menu); 

        if (getSupportFragmentManager().findFragmentById(android.R.id.content) == null) {
            ListFrag list = new ListFrag();
            getSupportFragmentManager().beginTransaction().replace(android.R.id.content, list).commit();
        }}}

My ListFragmentem:

public class ListFrag extends ListFragment {

    int Files = 0;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // TODO Auto-generated method stub

        getListView().setBackgroundResource(R.drawable.table);
        getListView().setDividerHeight(0);
        getListView().setCacheColorHint(0);

        View view = inflater.inflate(R.layout.main, null);

        return view;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        setListAdapter(new CustomListAdapter(getActivity(), getThemes()));
    }

    public String[] getThemes(){
                       ...
        return ...;
    }

主要的xml(用于编制带有定制清单的改编者清单的)

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="40dp"
    android:paddingTop="30dp"
    android:cacheColorHint="#00000000"
    android:layout_marginTop="100px"
     >


    <ImageView
        android:id="@+id/icon"
        android:layout_height="40dp"
        android:layout_width="40dp"
        android:src="@drawable/check" >
    </ImageView>

    <TextView
        android:id="@+id/label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@+id/label"
        android:paddingTop="6dp"
        android:paddingLeft="20dp"
        android:textSize="25px" >
    </TextView>

</LinearLayout>   

这一根基——门努·克斯姆勒应展示背景形象,并列出以下几块:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/back"
android:orientation="vertical"
android:layout_width="fill_parent" 
android:layout_height="fill_parent"
android:background="@drawable/back"
android:cacheColorHint="#00000000"
>

<fragment
      android:id="@+id/frag"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:name="com.osmgames.kartuves.ListFrag" >
</fragment>   

</LinearLayout>

这是我的风俗习惯:

public class CustomListAdapter extends ArrayAdapter<String> {
    private final Context context;
    private final String[] values;

    public CustomListAdapter(Context context, String[] values) {
        super(context, R.layout.main, values);
            this.context = context;
            this.values = values;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View rowView = inflater.inflate(R.layout.main, parent, false);

            TextView textView = (TextView) rowView.findViewById(R.id.label);

                ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);

                textView.setText(values[position]);

            imageView.setImageResource(R.drawable.check);

        return rowView;
    }
}

LOG:

05-07 11:49:43.017: D/AndroidRuntime(1216): Shutting down VM
05-07 11:49:43.017: W/dalvikvm(1216): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-07 11:49:43.047: E/AndroidRuntime(1216): FATAL EXCEPTION: main
05-07 11:49:43.047: E/AndroidRuntime(1216): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.osmgames.kartuves/com.osmgames.kartuves.menu}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
05-07 11:49:43.047: E/AndroidRuntime(1216):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-07 11:49:43.047: E/AndroidRuntime(1216):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-07 11:49:43.047: E/AndroidRuntime(1216):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-07 11:49:43.047: E/AndroidRuntime(1216):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-07 11:49:43.047: E/AndroidRuntime(1216):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-07 11:49:43.047: E/AndroidRuntime(1216):     at android.os.Looper.loop(Looper.java:123)
05-07 11:49:43.047: E/AndroidRuntime(1216):     at android.app.ActivityThread.main(ActivityThread.java:4627)
05-07 11:49:43.047: E/AndroidRuntime(1216):     at java.lang.reflect.Method.invokeNative(Native Method)
05-07 11:49:43.047: E/AndroidRuntime(1216):     at java.lang.reflect.Method.invoke(Method.java:521)
05-07 11:49:43.047: E/AndroidRuntime(1216):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-07 11:49:43.047: E/AndroidRuntime(1216):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-07 11:49:43.047: E/AndroidRuntime(1216):     at dalvik.system.NativeStart.main(Native Method)
05-07 11:49:43.047: E/AndroidRuntime(1216): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
05-07 11:49:43.047: E/AndroidRuntime(1216):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:582)
05-07 11:49:43.047: E/AndroidRuntime(1216):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
05-07 11:49:43.047: E/AndroidRuntime(1216):     at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
05-07 11:49:43.047: E/AndroidRuntime(1216):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
05-07 11:49:43.047: E/AndroidRuntime(1216):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
05-07 11:49:43.047: E/AndroidRuntime(1216):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
05-07 11:49:43.047: E/AndroidRuntime(1216):     at android.app.Activity.setContentView(Activity.java:1647)
05-07 11:49:43.047: E/AndroidRuntime(1216):     at com.osmgames.kartuves.menu.onCreate(menu.java:12)
05-07 11:49:43.047: E/AndroidRuntime(1216):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-07 11:49:43.047: E/AndroidRuntime(1216):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-07 11:49:43.047: E/AndroidRuntime(1216):     ... 11 more
05-07 11:49:43.047: E/AndroidRuntime(1216): Caused by: java.lang.IllegalStateException: Content view not yet created
05-07 11:49:43.047: E/AndroidRuntime(1216):     at android.support.v4.app.ListFragment.ensureList(ListFragment.java:328)
05-07 11:49:43.047: E/AndroidRuntime(1216):     at android.support.v4.app.ListFragment.getListView(ListFragment.java:222)
05-07 11:49:43.047: E/AndroidRuntime(1216):     at com.osmgames.kartuves.ListFrag.onCreateView(ListFrag.java:22)
05-07 11:49:43.047: E/AndroidRuntime(1216):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:845)
05-07 11:49:43.047: E/AndroidRuntime(1216):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1058)
05-07 11:49:43.047: E/AndroidRuntime(1216):     at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1156)
05-07 11:49:43.047: E/AndroidRuntime(1216):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:270)
05-07 11:49:43.047: E/AndroidRuntime(1216):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:558)
05-07 11:49:43.047: E/AndroidRuntime(1216):     ... 20 more

我看到,内容调查不是创建的,而是要理解为什么......。

最佳回答

最好从目录中:

Caused by: java.lang.IllegalStateException: Content view not yet created

你的问题是:

    getListView().setBackgroundResource(R.drawable.table);
    getListView().setDividerHeight(0);
    getListView().setCacheColorHint(0);

    View view = inflater.inflate(R.layout.main, null);

你在提出内容意见之前,试图听取名单。 将通货膨胀观点移至理论意见之前。

我认为,这也将消除关于粉碎分类的第二种错误。

问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签