Android view pager не раздувает виджеты в моей вкладке XML
I am new to android and I am having problem viewing my view contents in view pager layout. the following is my actiivity and adapter togather on the same file and the the viewpager xml and the details. my details.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> my viewPager xml file has the following contents <?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> </FrameLayout> my activity class has the following codes and also contain the adapter class and the code is as follows public class AddEdit extends AppCompatActivity { private static final int CONTACT_LOADER = 0; // private Uri contactUri; private SQLiteDatabase mDatabase; private Context mContext; 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); // load the contac // getSupportLoaderManager().initLoader( CONTACT_LOADER, null, this); } @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); } private ACursorWrapper queryInfo(String whereClause, String[] whereArgs){ mContext=getApplicationContext(); mDatabase = new AddressBookDatabaseHelper(mContext) .getWritableDatabase(); Cursor cursor = mDatabase.query( DatabaseDescription.Contact.TABLE_NAME, null, // columns - null selects all columns whereClause, whereArgs, null, // groupBy null, // having null // orderBy ); return new ACursorWrapper(cursor); } public List<Info> getInfos() { List<Info> information = new ArrayList<>(); ACursorWrapper cursor = queryInfo(null, null); try { cursor.moveToFirst(); while (!cursor.isAfterLast()) { information.add(cursor.getInfo()); cursor.moveToNext(); } } finally { cursor.close(); } return information; } public Info getInfo(int id) { ACursorWrapper cursor = queryInfo( DatabaseDescription.Contact._ID + " = ?", new String[] { id+"" } ); try { if (cursor.getCount() == 0) { return null; } cursor.moveToFirst(); return cursor.getInfo(); } finally { cursor.close(); } } public class pageViewAdapter1 extends PagerAdapter { Context context; 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 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) { 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); } } } could some one tell me why I don't see widgets in detail.xml after I inflated them.Please try to understand that I am just beginner trying to learn. thank you
Что я уже пробовал:
когда я запускаю код виджеты в detail.xml не надуваются.
David Crow
Я не вижу, где вы надуваетесь details.xml
- Это намеренно?
Amanuel Negash
он находится в общедоступном объекте instantiateItem(контейнер ViewGroup, int position) {
mInflater=(LayoutInflater)
context.getSystemService(контекст.LAYOUT_INFLATER_SERVICE);
View item_view=mInflater.inflate(R. layout.деталь,контейнер,ложь);
David Crow
Один detail
, другой-это details
.