メインアクティビティにはサイドバーがあります。そのサイドバーに、secondactivity のコンテンツを配置する必要があります。Secondactivity は、データベースから取得したデータを含む ListActivity を拡張します。
主な活動:
setContentView(R.layout.main);
RelativeLayout mainContainer = (RelativeLayout) findViewById(R.id.MainContainer);
LayoutInflater layoutinflate = getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutinflate.inflate(R.layout.cameralist, null);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams (RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.FILL_PARENT);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
view.setLayoutParams(params);
mainContainer.addView(view);
main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/MainContainer"
android:layout_width="wrap_content"
android:layout_height="fill_parent">
</RelativeLayout>
cameralist.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Sidebar"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#000000">
<TextView
android:id="@+id/CameraHeading"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text=" Camera List "
android:textAppearance="?android:attr/textAppearanceLarge"
android:ellipsize="middle"/>
<com.fs.menuanimation.ViewCamera
android:id="@+id/CamList"
android:layout_width="wrap_content"
android:layout_height="fill_parent"/>
セカンド アクティビティ:
public class ViewCamera extends ListActivity {
String DB = AddCamera.DB_NAME;
String TABLE_NAME = AddCamera.TABLE_NAME;
ArrayList<String> results = new ArrayList<String>();
//SQLiteDatabase sampleDB = null;
SQLiteDatabase sampleDB = AddCamera.SMMSLITEDB;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sampleDB = this.openOrCreateDatabase(DB, MODE_PRIVATE, null);
Cursor c = sampleDB.rawQuery("SELECT CameraName FROM " + TABLE_NAME , null);
if (c != null ) {
if (c.moveToFirst()) {
do {
String CameraName = c.getString(c.getColumnIndex("CameraName"));
//int age = c.getInt(c.getColumnIndex("Age"));
results.add(CameraName);
}while (c.moveToNext());
}
}
this.setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,results));
}
}
誰でも私を助けることができますか?