我正在尝试使用Android Wear创建一个简单的GridPager。问题是我可以刷过不同的行和列,但卡片不可见.. 此外,我在日志中收到此警告:
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}
代码活动:
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);
}
}
我希望有人可以帮助我!
答案 0 :(得分:1)
我不得不删除:
@Override
public boolean isViewFromObject(View view, Object o) {
return view.equals(o);
}
显然,这一直都是假的。