在 mainactivity 我有侧边栏。在那个侧边栏中,需要放置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);
主.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>
相机列表.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"/>
第二活动:
公共类 ViewCamera 扩展 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));
}
}
谁能帮我。