您好,在我目前的项目中,我需要为平板电脑创建一个特定的设计。首先让我告诉你设计。我需要创建一个活动,其中应该有三个片段
1)第一片段 - >它应该包含一个GridView - Single colomn。
2)第二片段 - >如果用户在网格视图中单击图像,则应在此第二个框架中生成自定义列表视图。
3)第三片段 - >如果用户在前一个第二个片段中选择单个列表,则应在此详细信息列表视图中显示该列表。
我做的是,我创建了一个Activity,而xml是
<LinearLayout 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:baselineAligned="false"
android:orientation="horizontal"
android:weightSum="3"
tools:context="caresynchrony.sanvishealth.com.im026.ovn_tablet.SingleResident">
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight=".5"
android:orientation="vertical">
<GridView
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/gridViewHome"
android:columnCount="1"
android:columnWidth="250dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp"
android:listSelector="@drawable/selector_bt"
/>
</LinearLayout>
<FrameLayout
android:id="@+id/listFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.2"/>
<FrameLayout
android:id="@+id/detailFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.3"/>
</LinearLayout>
类文件是
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_single_resident);
GridView gridview = (GridView)findViewById(R.id.gridViewHome);
DashBoardAdaptor adapter = new DashBoardAdaptor(this);
gridview.setAdapter(adapter);
gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch (position) {
case 0:
break;
case 1:
Fragment fragment = new CareAlert();
FragmentManager fragmentManager =getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.listFragment, fragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
//changeFragment(fragment,R.id.listFragment);
break;
第二个frament xml文件是,
<LinearLayout 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"
tools:context="caresynchrony.sanvishealth.com.im026.ovn_tablet.CareAlert">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_marginTop="20dp"
android:weightSum="2">
<TextView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:text="Recent Alerts"
android:layout_weight=".2"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:background="@color/terms_text_color"
android:textColor="@color/bt_text"
android:id="@+id/textView3"
android:layout_gravity="left|top" />
<ListView
android:id="@+id/listViewCareList"
android:layout_width="match_parent"
android:layout_weight="1.8"
android:layout_height="0dp"
/>
</LinearLayout>
</LinearLayout>
适配器文件是
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// v = minflater.inflate(R.layout.carerowlist,parent,false);
v = inflater.inflate(row, parent,false);
holder.name = (TextView) v.findViewById(R.id.textViewtype);
holder.dob = (TextView) v.findViewById(R.id.textViewdate);
holder.msg = (TextView) v.findViewById(R.id.textViewmsg);
holder.priority = (TextView) v.findViewById(R.id.textViewpriorityllevel);
holder.priorityimage=(ImageView)v.findViewById(R.id.imageViewpriority);
v.setTag(holder);
当我运行我的项目时,我收到了这些错误
Process: caresynchrony.sanvishealth.com.im026.ovn_tablet, PID: 2536
android.view.InflateException: Binary XML file line #6: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:621)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:670)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:695)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:756)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at adapter.CareAlertAdapter.getView(CareAlertAdapter.java:60)
at android.widget.AbsListView.obtainView(AbsListView.java:2263)
at android.widget.ListView.makeAndAddView(ListView.java:1790)
at android.widget.ListView.fillDown(ListView.java:691)
at android.widget.ListView.fillFromTop(ListView.java:752)
at android.widget.ListView.layoutChildren(ListView.java:1616)
at android.widget.AbsListView.onLayout(AbsListView.java:2091)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1660)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1436)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
注意:各种设计意味着,对于网格中的第一项,列表仅包含3个文本视图,但对于网格中的第二个和第一个项目,它有6个视图。我怎样才能做到这一点。 如果您无法理解我的问题,请在下面发表评论。