レイアウトを 2 つの部分に分割したいのですが、最初はアナログ時計のみ、2 つ目はリストビューが必要です。
xml ファイル ;
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<AnalogClock
android:id="@+id/analogClock1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/day_plan" />
</LinearLayout>
含むレイアウトの xml ;
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/countryTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:textSize="20sp"
android:textColor="@android:color/white"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"/>
この時計の下に、データベースからのイベントのリストを表示したい:
public class Clock extends ListActivity {
public static final String ROW_ID = "row_id";
private ListView conListView;
private CursorAdapter conAdapter;
public String opis;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.morning_clock);
conListView=getListView();
conListView.setOnItemClickListener(viewConListener);
AnalogClock ac = (AnalogClock) findViewById(R.id.analogClock1);
// map each name to a TextView
String[] from = new String[] { "event" };
int[] to = new int[] { R.id.countryTextView };
conAdapter = new SimpleCursorAdapter(Clock.this, R.layout.morning_clock, null, from, to);
setListAdapter(conAdapter); // set adapter
}
@Override
protected void onResume()
{
super.onResume();
new GetEvents().execute((Object[]) null);
}
@Override
protected void onStop()
{
Cursor cursor = conAdapter.getCursor();
if (cursor != null)
cursor.deactivate();
conAdapter.changeCursor(null);
super.onStop();
}
private class GetEvents extends AsyncTask<Object, Object, Cursor>
{
DatabaseConnector dbConnector = new DatabaseConnector(Clock.this);
@Override
protected Cursor doInBackground(Object... params)
{
Intent a = getIntent();
String d_m_y = a.getStringExtra("d_m_y");
dbConnector.open();
return dbConnector.getdate(d_m_y);
}
@Override
protected void onPostExecute(Cursor result)
{
conAdapter.changeCursor(result); // set the adapter's Cursor
dbConnector.close();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.dayplan_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
Intent addEvent = new Intent(Clock.this, AddEvent.class);
startActivity(addEvent);
return super.onOptionsItemSelected(item);
}
OnItemClickListener viewConListener = new OnItemClickListener()
{
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3)
{
Intent viewEvent = new Intent(Clock.this, ViewEvent.class);
viewEvent.putExtra(ROW_ID, arg3);
startActivity(viewEvent);
}
};
}
そしてエラーが発生します:
01-02 21:57:50.645: E/AndroidRuntime(1047): FATAL EXCEPTION: main
01-02 21:57:50.645: E/AndroidRuntime(1047): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.examples.android.calendar/com.examples.android.calendar.Clock}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
01-02 21:57:50.645: E/AndroidRuntime(1047): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
01-02 21:57:50.645: E/AndroidRuntime(1047): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
01-02 21:57:50.645: E/AndroidRuntime(1047): at android.app.ActivityThread.access$600(ActivityThread.java:130)
01-02 21:57:50.645: E/AndroidRuntime(1047): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
01-02 21:57:50.645: E/AndroidRuntime(1047): at android.os.Handler.dispatchMessage(Handler.java:99)
01-02 21:57:50.645: E/AndroidRuntime(1047): at android.os.Looper.loop(Looper.java:137)
01-02 21:57:50.645: E/AndroidRuntime(1047): at android.app.ActivityThread.main(ActivityThread.java:4745)
01-02 21:57:50.645: E/AndroidRuntime(1047): at java.lang.reflect.Method.invokeNative(Native Method)
01-02 21:57:50.645: E/AndroidRuntime(1047): at java.lang.reflect.Method.invoke(Method.java:511)
01-02 21:57:50.645: E/AndroidRuntime(1047): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-02 21:57:50.645: E/AndroidRuntime(1047): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-02 21:57:50.645: E/AndroidRuntime(1047): at dalvik.system.NativeStart.main(Native Method)