Java Android图像滑块文本更改
我已经用过android的图像刷。很好用。但我需要一些定制。我需要文本和按钮波纹管图像和文本应根据图像的变化刷卡。文本和按钮不应滑动 我所做的是在fragment_页面上放置两个文本视图和按钮Java Android图像滑块文本更改,java,android,Java,Android,我已经用过android的图像刷。很好用。但我需要一些定制。我需要文本和按钮波纹管图像和文本应根据图像的变化刷卡。文本和按钮不应滑动 我所做的是在fragment_页面上放置两个文本视图和按钮 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="@drawable/background"
android:weightSum="1">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="wrap_content"
android:layout_height="217dp"
android:layout_weight="0.71">
</android.support.v4.view.ViewPager>
<TextView
style="@style/bigFont"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/textBold"
android:layout_marginTop="20dp"
android:textColor="@color/text_color"
android:layout_centerHorizontal="true"/>
<TextView
style="@style/smallFont"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/textsmall"
android:layout_marginTop="20dp"
android:layout_below="@+id/textBold"
android:textColor="@color/text_color"
android:layout_centerHorizontal="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="REGISTER NOW"
android:id="@+id/button2"
android:background="@drawable/button_design"
android:textColor="@color/text_color"
android:padding="@dimen/abc_action_bar_content_inset_material"
android:layout_below="@+id/textsmall"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp" />
</LinearLayout>
}
检查settext方法。在这里,我试图更改文本,但问题是这个上下文在另一个类中,它是静态的,所以我无法更改它。如何使其工作?您可以使用“查看寻呼机”的“页面列表”用户,并通过getCurrentItem更改文本视图。您可以解释一下吗?因为我还没有得到。正如您所提到的,实现了侦听器。你能提供一些代码让我能正确理解吗?干杯。。喜欢编码。。。!嗨@RahulPatel你是怎么修好的?因为我面临同样的问题,但问题是getItem()调用了两次,并且在没有显示textview1的情况下从textview0跳转到textview2。。你能帮我吗。。。以下是主题:
package com.example.rocku28.mdt;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class Slider extends FragmentActivity {
static final int NUM_ITEMS = 4;
ImageFragmentPagerAdapter imageFragmentPagerAdapter;
ViewPager viewPager;
TextView boldTxt,smallTxt;
Button regButton;
public static final String[] IMAGE_NAME = {"one", "two", "three", "four"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_pager);
boldTxt = (TextView) findViewById(R.id.textBold);
smallTxt = (TextView) findViewById(R.id.textsmall);
imageFragmentPagerAdapter = new ImageFragmentPagerAdapter(getSupportFragmentManager());
viewPager = (ViewPager) findViewById(R.id.pager);
viewPager.setAdapter(imageFragmentPagerAdapter);
}
public static class ImageFragmentPagerAdapter extends FragmentPagerAdapter {
public ImageFragmentPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public int getCount() {
return NUM_ITEMS;
}
@Override
public Fragment getItem(int position) {
SwipeFragment fragment = new SwipeFragment();
return SwipeFragment.newInstance(position);
}
}
public static class SwipeFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View swipeView = inflater.inflate(R.layout.swipe_fragment, container, false);
ImageView imageView = (ImageView) swipeView.findViewById(R.id.imageView);
Bundle bundle = getArguments();
int position = bundle.getInt("position");
String imageFileName = IMAGE_NAME[position];
int imgResId = getResources().getIdentifier(imageFileName, "drawable", "com.example.rocku28.mdt");
imageView.setImageResource(imgResId);
setText(position);
return swipeView;
}
public void setText(int position){
// here I tried to change text on text view
switch (position){
case 0:
new Slider().boldTxt.setText(R.string.verify_licence);
new Slider().smallTxt.setText(R.string.take_back_picture);
break;
case 1:
// boldTxt.setText(R.string.verify_licence);
// smallTxt.setText(R.string.take_front_picture);
break;
case 2:
// boldTxt.setText(R.string.dashboard);
// smallTxt.setText(R.string.choose_option_to_call);
break;
case 3:
// boldTxt.setText(R.string.helpline);
// smallTxt.setText(R.string.call_call_center);
break;
}
}
static SwipeFragment newInstance(int position) {
SwipeFragment swipeFragment = new SwipeFragment();
Bundle bundle = new Bundle();
bundle.putInt("position", position);
swipeFragment.setArguments(bundle);
return swipeFragment;
}
}