我是Android的新手,我在浏览寻呼机布局中查看我的视图内容时遇到问题。以下是我的活动和适配器在同一个文件和ViewPager xml以及详细信息上 my detail.xml
<FrameLayout
android:id="@+id/detailsScrollView"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:useDefaultMargins="true"
android:paddingTop="70dp">
<TextView
android:id="@+id/nameLabelTextView1"
style="@style/ContactLabelTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="0"
android:text="@string/label_name"/>
<TextView
android:id="@+id/nameTextView1"
style="@style/ContactTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="0"/>
<TextView
android:id="@+id/phoneLabelTextView1"
style="@style/ContactLabelTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="1"
android:text="@string/label_phone"/>
<TextView
android:id="@+id/phoneTextView1"
style="@style/ContactTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="1"/>
<TextView
android:id="@+id/emailLabelTextView1"
style="@style/ContactLabelTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="2"
android:text="@string/label_email"/>
<TextView
android:id="@+id/emailTextView1"
style="@style/ContactTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="2"/>
<TextView
android:id="@+id/streetLabelTextView1"
style="@style/ContactLabelTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="3"
android:text="@string/label_street"/>
<TextView
android:id="@+id/streetTextView1"
style="@style/ContactTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="3"/>
<TextView
android:id="@+id/cityLabelTextView1"
style="@style/ContactLabelTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="4"
android:text="@string/label_city"/>
<TextView
android:id="@+id/cityTextView1"
style="@style/ContactTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="4"/>
<TextView
android:id="@+id/stateLabelTextView1"
style="@style/ContactLabelTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="5"
android:text="@string/label_state"/>
<TextView
android:id="@+id/stateTextView1"
style="@style/ContactTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="5"/>
<TextView
android:id="@+id/zipLabelTextView1"
style="@style/ContactLabelTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="6"
android:text="@string/label_zip"/>
<TextView
android:id="@+id/zipTextView1"
style="@style/ContactTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="6"/>
</GridLayout>
</FrameLayout>
我的 viewPager.xml 文件包含以下内容
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fitsSystemWindows="true"
android:id="@+id/addEdit">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/toolbar1"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"
></android.support.v7.widget.Toolbar>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/slide"
android:visibility="visible">
</android.support.v4.view.ViewPager>
我的活动类具有以下代码,并且还包含适配器类 代码如下
public class AddEdit extends AppCompatActivity
{
ViewPager mViewPager;
pageViewAdapter1 slider;
List<Info> informatn = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_edit);
Toolbar tool=(Toolbar) findViewById(R.id.toolbar1);
mViewPager=(ViewPager) findViewById(R.id.slide);
slider=new pageViewAdapter1(this);
mViewPager.setAdapter(slider);
setSupportActionBar(tool);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater findMenuItems = getMenuInflater();
findMenuItems.inflate(R.menu.fragment_details_menu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_delete:
Toast.makeText(AddEdit.this,"delete
",Toast.LENGTH_LONG).show();
break;
case R.id.action_edit:
finish();
break;
}
return super.onOptionsItemSelected(item);
}
}
public class pageViewAdapter1 extends PagerAdapter {
Context context;
public pageViewAdapter1(Context context) {
this.context = context;
}
@Override
public int getCount() {
return informatn.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return (view==(View)object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
private LayoutInflater mInflater;
private TextView nameTextView; // displays contact's name
private TextView phoneTextView; // displays contact's phone
private TextView emailTextView; // displays contact's email
private TextView streetTextView; // displays contact's street
private TextView cityTextView; // displays contact's city
private TextView stateTextView; // displays contact's state
private TextView zipTextView; // displays contact's zip
mInflater=(LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View item_view=mInflater.inflate(R.layout.detail,container,false);
// get the EditTexts
nameTextView = (TextView)
item_view.findViewById(R.id.nameTextView1);
phoneTextView = (TextView)
item_view.findViewById(R.id.phoneTextView1);
emailTextView = (TextView)
item_view.findViewById(R.id.emailTextView1);
streetTextView = (TextView)
item_view.findViewById(R.id.streetTextView1);
cityTextView = (TextView)
item_view.findViewById(R.id.cityTextView1);
stateTextView = (TextView)
item_view.findViewById(R.id.stateTextView1);
zipTextView = (TextView) item_view.findViewById(R.id.zipTextView1);
informatn=getInfos();
nameTextView.setText(informatn.get(position).name);
phoneTextView.setText(informatn.get(position).phone);
emailTextView.setText(informatn.get(position).eamil);
streetTextView.setText(informatn.get(position).street);
cityTextView.setText(informatn.get(position).City);
stateTextView.setText(informatn.get(position).state);
zipTextView.setText(informatn.get(position).zip);
container.addView(item_view);
return item_view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object
object) {
container.removeView((FrameLayout)object);
}
}
}
有人可以告诉我为什么在我给他们充气之后我不会在detail.xml中看到小部件。请尝试理解我只是初学者想要学习。谢谢