gpt4 book ai didi

带有页面指示器的 Android View 寻呼机

转载 作者:IT老高 更新时间:2023-10-28 22:00:36 42 4
gpt4 key购买 nike

我需要在带有图像的 View 寻呼机文件中获取页面指示器。这是我的代码。

public class IndicatorActivity extends Activity {


/** Called when the activity is first created. */
@Override

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

MyPagerAdapter adapter = new MyPagerAdapter();
ViewPager myPager = (ViewPager) findViewById(R.id.pager);
myPager.setAdapter(adapter);
myPager.setCurrentItem(0);
TitlePageIndicator indicator = (TitlePageIndicator)findViewById(R.id.indicat);
indicator.setViewPager( myPager );
}
}

在此代码中,我在 TitlePageIndicator indicator = (TitlePageIndicator)findViewById(R.id.indicat); 中遇到错误,因为 TitlePageIndicator 无法解析为类型。这是什么错误。我该如何解决?

这是我的 xml 代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<com.viewpagerindicator.TitlePageIndicator
android:id="@+id/indicat"
android:layout_height="wrap_content"
android:layout_width="fill_parent" />
</LinearLayout>

TitlePageIndicator需要写什么代码?我想在不使用 fragment 的情况下做到这一点

我还创建了一个类如:

class MyPagerAdapter extends PagerAdapter {

private static Integer[] titles = new Integer[]
{
R.drawable.jk,R.drawable.lm,R.drawable.no
};

public int getCount() {
return 3;
}

public Object instantiateItem(View collection, int position) {

LayoutInflater inflater = (LayoutInflater) collection.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view;
ImageView iv;

view = inflater.inflate(R.layout.first, null);

((ViewPager) collection).addView(view, 0);
switch (position) {
case 0:
iv = (ImageView)view.findViewById(R.id.imageView1);
iv.setImageResource(titles[position]);
break;
case 1:
iv = (ImageView)view.findViewById(R.id.imageView1);
iv.setImageResource(titles[position]);
break;
case 2:
iv = (ImageView)view.findViewById(R.id.imageView1);
iv.setImageResource(titles[position]);
break;
}
return view;
}

public void destroyItem(View arg0, int arg1, Object arg2) {
((ViewPager) arg0).removeView((View) arg2);

}



public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == ((View) arg1);

}

}

除了这门课,我还想做点什么吗?

提前感谢您的帮助

最佳答案

更新: 2017 年 3 月 22 日

主要 fragment 布局:

       <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<RadioGroup
android:id="@+id/page_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:layout_marginBottom="@dimen/margin_help_container"
android:orientation="horizontal">

<RadioButton
android:id="@+id/page1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true" />

<RadioButton
android:id="@+id/page2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<RadioButton
android:id="@+id/page3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RadioGroup>
</FrameLayout>

像这样在 fragment 上设置 View 和事件:

        mViewPaper = (ViewPager) view.findViewById(R.id.viewpager);
mViewPaper.setAdapter(adapder);

mPageGroup = (RadioGroup) view.findViewById(R.id.page_group);
mPageGroup.setOnCheckedChangeListener(this);

mViewPaper.addOnPageChangeListener(this);

*************************************************
*************************************************

@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}

@Override
public void onPageSelected(int position) {
// when current page change -> update radio button state
int radioButtonId = mPageGroup.getChildAt(position).getId();
mPageGroup.check(radioButtonId);
}

@Override
public void onPageScrollStateChanged(int state) {
}

@Override
public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
// when checked radio button -> update current page
RadioButton checkedRadioButton = (RadioButton)radioGroup.findViewById(checkedId);
// get index of checked radio button
int index = radioGroup.indexOfChild(checkedRadioButton);

// update current page
mViewPaper.setCurrentItem(index), true);
}

自定义复选框状态:Custom checkbox image android

Viewpager 教程:http://architects.dzone.com/articles/android-tutorial-using

enter image description here

关于带有页面指示器的 Android View 寻呼机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12316931/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com