1
我正在嘗試使用Android Wear製作簡單的GridPager。問題是,我可以通過不同的行和列刷卡,但卡是不可見的.. 除了我得到的日誌中這樣的警告:CardFragment在FragmentGridPagerAdapter中未顯示 - Android Wear
06-16 07:49:55.883 1739-1739/ W/GridViewPager﹕ Unknown child view, not claimed by adapter: android.support.wearable.view.CardScrollView{2231190b V.E..... ......I. 0,0-0,0}
Code活動:
public class MainActivity extends FragmentActivity {
private TextView mTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
@Override
public void onLayoutInflated(WatchViewStub stub) {
final GridViewPager mGridPager = (GridViewPager) stub.findViewById(R.id.pager);
mGridPager.setAdapter(new SampleGridPagerAdapter(MainActivity.this, getFragmentManager()));
}
});
}
}
佈局:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.wearable.view.GridViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
代碼適配器:
public class SampleGridPagerAdapter extends FragmentGridPagerAdapter {
private final Context mContext;
private ArrayList<SimpleRow> mPages;
public SampleGridPagerAdapter(Context context, FragmentManager fm) {
super(fm);
mContext = context;
initPages();
}
private void initPages() {
Log.i("adapter", "init pages");
mPages = new ArrayList<>();
SimpleRow row1 = new SimpleRow();
row1.addPages(new SimplePage("Title1", "Text1", R.drawable.ic_full_cancel, R.drawable.ic_full_sad));
row1.addPages(new SimplePage("Title2", "Text2", R.drawable.ic_full_cancel, R.drawable.ic_full_sad));
SimpleRow row2 = new SimpleRow();
row2.addPages(new SimplePage("Title3", "Text3", R.drawable.ic_full_cancel, R.drawable.ic_full_sad));
SimpleRow row3 = new SimpleRow();
row3.addPages(new SimplePage("Title4", "Text4", R.drawable.ic_full_cancel, R.drawable.ic_full_sad));
SimpleRow row4 = new SimpleRow();
row4.addPages(new SimplePage("Title5", "Text5", R.drawable.ic_full_cancel, R.drawable.ic_full_sad));
row4.addPages(new SimplePage("Title6", "Text6", R.drawable.ic_full_cancel, R.drawable.ic_full_sad));
mPages.add(row1);
mPages.add(row2);
mPages.add(row3);
mPages.add(row4);
}
@Override
public int getRowCount() {
return mPages.size();
}
@Override
public Drawable getBackgroundForPage(int row, int column) {
return mContext.getDrawable(R.drawable.bg_alarm_day);
}
@Override
public int getCurrentColumnForRow(int row, int currentColumn) {
return currentColumn;
}
@Override
public int getColumnCount(int row) {
return mPages.get(row).size();
}
@Override
public Fragment getFragment(int row, int column) {
SimplePage page = mPages.get(row).getPages(column);
return CardFragment.create(page.getmTitle(), page.getmText());
}
@Override
public boolean isViewFromObject(View view, Object o) {
return view.equals(o);
}
}
我希望有人能幫助我在這裏!
Hej,你可以發佈你的SimpleRow類嗎? :)) – hkop