80,351
社区成员
发帖
与我相关
我的任务
分享
public class TimeSchedulerActivity extends ActionBarActivity {
//TimeTrackerAdapter timeTrackerAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_time_scheduler);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
ListView listView = (ListView)findViewById(R.id.time_list);
TimeTrackerAdapter timeTrackerAdapter = new TimeTrackerAdapter();
listView.setAdapter(timeTrackerAdapter); // 这里出错了,程序直接退出
}
..............
}
public class TimeTrackerAdapter extends BaseAdapter {
private ArrayList<TimeRecord> times = new ArrayList<TimeRecord>();
public TimeTrackerAdapter() {
times.add(new TimeRecord("38:23", "Feeling good!"));
times.add(new TimeRecord("49:01", "Tired. Needed some tea!"));
times.add(new TimeRecord("29:42", "Exhausted!"));
}
....................
}
public class TimeRecord {
private String time;
private String notes;
public TimeRecord(String time, String notes)
{
this.time = time;
this.notes = notes;
}
.............
}
<?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>
<TextView
android:id="@+id/text_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/title_str" />
大家忽略掉,那是我加上用来调试的
<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>