DialogFragment的奇怪行为

时间:2014-05-30 10:29:52

标签: android fragment

早上好,这里我有一个DialogFragment,我正在尝试自定义它,:

问题是,我试图在编辑文本中显示自定义消息,每当标签更改时,它在向前标签1by1上工作正常,但在标签回来时,它变成了**** 然后有时候它有效,有时候没有,我想我的代码不稳定或者我错过了一些东西?

 public class QuickContactFragment extends DialogFragment {
View view;
private PagerSlidingTabStrip tabs;
private ViewPager pager;
private ContactPagerAdapter adapter;
ViewGroup container;
LayoutInflater inflater;
public static QuickContactFragment newInstance() {
    QuickContactFragment f = new QuickContactFragment();
    return f;

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle 
 savedInstanceState) {



    if (getDialog() != null) {
        getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);

 getDialog().getWindow().setBackgroundDrawableResource(android.R.color.transparent);

     }

    View root = inflater.inflate(R.layout.fragment_quick_contact, container, 
false);
    View tv = root.findViewById(R.id.quickcontacttext);
    ((TextView)tv).setText("This is an instance of MyDialogFragment");


    tabs = (PagerSlidingTabStrip) root.findViewById(R.id.tabs);
    pager = (ViewPager) root.findViewById(R.id.pager);
    adapter = new ContactPagerAdapter();

    pager.setAdapter(adapter);

    tabs.setViewPager(pager);

    return root;
}


@SuppressWarnings("deprecation")
@Override
public void onStart() {

BusProvider.getInstance().register(this);
    super.onStart();

    // change dialog width
    if (getDialog() != null) {

        int fullWidth = getDialog().getWindow().getAttributes().width;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
            Display display = 
 getActivity().getWindowManager().getDefaultDisplay();
            Point size = new Point();
            display.getSize(size);
            fullWidth = size.x;
        } else {
            Display display = 
 getActivity().getWindowManager().getDefaultDisplay();
            fullWidth = display.getWidth();
        }

        final int padding = (int) 
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, getResources()
                .getDisplayMetrics());

        int w = fullWidth - padding;
        int h = getDialog().getWindow().getAttributes().height;

        getDialog().getWindow().setLayout(w, h);
    }
}

这里是我的Icon标签提供程序:

 public class ContactPagerAdapter extends PagerAdapter implements IconTabProvider {

    private final int[] ICONS = { R.drawable.ic_launcher_gplus, 
  R.drawable.ic_launcher_gmail,
            R.drawable.ic_launcher_gmaps, 
  R.drawable.ic_launcher_chrome };

    public ContactPagerAdapter() {
        super();
    }

    //here is implemention too

    //here shows how many tabs should it predict.. i can set N=0 and every 
 time a notification comes, set N=N+1, and then whenever delete happenes, N=N-1 ;D
    @Override
    public int getCount() {
        return ICONS.length;
    }



    @Override
    public int getPageIconResId(int position) {





 return ICONS[position];
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        // looks a little bit messy here
          TextView v = new TextView(getActivity());
         v.setBackgroundResource(R.color.background_window);
        View tv = getView().findViewById(R.id.quickcontacttext);


            if(position==1){
                v.setText("this is page 0 :D");
                ((TextView)tv).setText("aaand it worked 0");
            FRQTabImage(position);
            }

            else{
                v.setText("this is page NOt 1:D");
                ((TextView)tv).setText("aaand it worked 1");
            FRQTabImage(position);
            }

0 个答案:

没有答案