本帖最后由 linqo 于 2014-05-08 14:26:04 编辑

解决方案 »

  1.   

    BaseAdapter写错了class testBaseAdapter extends BaseAdapter{ @Override
    public int getCount() {
    // TODO Auto-generated method stub
    return 0;
    } @Override
    public Object getItem(int position) {
    // TODO Auto-generated method stub
    return null;
    } @Override
    public long getItemId(int position) {
    // TODO Auto-generated method stub
    return 0;
    } @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    return null;
    }

    }
      

  2.   

    上网找找就有BaseAdapter怎么写的,布局和内容在外面利用变量保存,然后通过Getview来循环显示,具体需要怎么显示都能自己来写,自由度和可变性都比较好getCount()  return 数组或者列表的长度getItem return 数组[position]或者列表.get(position)getItemId return postiiongetview  很多种写法可以上网找找里面的Position对应你数组或者列表的其中一个元素
      

  3.   

    http://www.cnblogs.com/mandroid/archive/2011/04/05/2005525.html 看看这个例子吧
      

  4.   

    TimeTrackerAdapter timeTrackerAdapter = new TimeTrackerAdapter(this);  试试 
      

  5.   


    AndroidManifest.xml内容如下,应该是注册了的
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.dailytimetracker"
        android:versionCode="1"
        android:versionName="1.0" >    <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="19" />    <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="com.example.dailytimetracker.TimeSchedulerActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application></manifest>
      

  6.   

    这是“Head First Android Development” 上的一个例子,但是它没有贴完全的代码,我照着它的描述写的,java代码是一样的,它贴出来了,其它的树上没有贴,可能有稍微的不一样,编译没有问题,运行就出错,把出错的那一行注掉就OK,但是是个空窗口,什么都没有
      

  7.   


    ..亲,你注释了setadapter后不报错,因为你没有引用那个adapter.所以我跟你说你的baseadapter写错了
      

  8.   

    lz还是先去看下Fragment吧。
    报错是因为listview为null而非adapter
      

  9.   

    是的, ListView listView = (ListView)findViewById(R.id.time_list); 为空,所以不是setAdapter的问题。查了不少文档,了解到findViewById返回null一般来讲是由以下几种原因造成的:
    1. findViewById在setContentView(R.layout.main);之前.
    2. 使用了id的旧风格 <Button id="@+id/btn_ok" />
    3. 没有重写BottomTab方法 
    4. .clean一下工程,让ID重新生成
    5. 在另一个view的元素应该用baseView.findViewById()来拿还有这样的提示:
    1、对于一个没有被载入或者想要动态载入的界面,都需要使用LayoutInflater.inflate()来载入;
    2、对于一个已经载入的界面,就可以使用Activiyt.findViewById()方法来获得其中的界面元素。我遇到的问题可能是上面的第五条,也可能是下面的两条,但是刚接触Androiad,实在是搞不清楚,贴出我的layout文件如下,有劳大家帮看看activity_time_scheduler.xml<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.example.dailytimetracker.TimeSchedulerActivity"
        tools:ignore="MergeRootFrame" />
    fragment_time_scheduler.xml<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.example.dailytimetracker.TimeSchedulerActivity$PlaceholderFragment" >
        
    <TextView
        android:id="@+id/text_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/title_str" /> <ListView
        android:id="@+id/time_list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/text_title"
        android:layout_alignParentBottom="true"
        android:layout_alignRight="@+id/text_title" > </ListView></RelativeLayout>time_list_item.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:orientation="vertical" >
        
        <TextView android:id="@+id/time_view"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textSize="18sp"
            android:paddingBottom="5dp" />
        
        <TextView android:id="@+id/notes_view"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textSize="12sp" />
    </LinearLayout>
      

  10.   

    lz查的文档都很老了,给个提示:listview的初始化和setadapter等操作都放到Fragment里。
      

  11.   

    抱歉,fragment_time_scheduler.xml里面的    <TextView
            android:id="@+id/text_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/title_str" />
    大家忽略掉,那是我加上用来调试的
      

  12.   


    谢谢,Fragment确实还不是太懂,我查一下具体是怎么用,不懂的东西太多了
      

  13.   

    报告一下,诚如hjywyj的提示,把listview的初始化和setadapter放到Fragment里面以后就好了。所以之前的问题可能是因为findViewById是在activity的onCreate里面调用的,默认为activity的findViewById,但我的ListView是放在Fragment的xml里面的,所以找不到