我的视图包含XML文件定义的LinearLayout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="5dip"
android:paddingBottom="5dip"
android:background="#CCC">
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/hours"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</LinearLayout>
</LinearLayout>
只是在屏幕左侧添加了一个栏。 现在,根据用户的输入,我想在栏旁边添加dynimally linearlayouts。
显示栏的代码是:
public class MainActivity extends ListActivity {
private static int HOURS_PER_DAY = 24;
Context context = this;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
setListAdapter(new ListAdapter() {
public boolean areAllItemsEnabled() {
return false;
}
public boolean isEnabled(int arg0) {
return false;
}
public int getCount() {
return HOURS_PER_DAY;
}
public Object getItem(int arg0) {
return null;
}
public long getItemId(int arg0) {
return 0;
}
public int getItemViewType(int arg0) {
return 0;
}
public View getView(int position, View arg1, ViewGroup arg2) {
LayoutInflater inflater = getLayoutInflater();
View listItem = (View) inflater.inflate(R.layout.list,getListView(),false);
return listItem;
}
public int getViewTypeCount() {
return 1;
}
public boolean hasStableIds() {
return false;
}
public boolean isEmpty() {
return false;
}
public void registerDataSetObserver(DataSetObserver arg0) {
}
public void unregisterDataSetObserver(DataSetObserver arg0) {
}
});
在java代码中,我想在xml文件中定义的一个旁边添加新的linearlayouts