Issue with doing fragment transaction inside a getview of baseadapter?

402 views Asked by At

Have a Linearlayout inside to that having 3 different framelayout. In that frame layout am adding the fragments dynamically inside the adaper getview. Initially the adapter getview gets called twice. Then later it called once for every flip. Have added the flip view functionality along with that. In that for first screen before any flip, the dynamic fragments are not getting added to the main view. But for the later flipped screens it's getting added properly.

Please help me on this.

Thanks in advance.

public class MainActivity extends Activity {

private FragmentTransaction fragMentTra = null;
protected FlipViewController flipView;
private LayoutInflater inflater;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    flipView = new FlipViewController(this);

    flipView.setAdapter(new BaseAdapter() {
        public int getCount() {
            return 2;
        }

        public Object getItem(int position) {
            return position;
        }

        public long getItemId(int position) {
            return position;
        }

        @SuppressLint("NewApi")
        public View getView(int position, View convertView, ViewGroup parent) {

            View layout = convertView;


            if (convertView == null) {
                inflater = LayoutInflater.from(parent.getContext());
                layout = inflater.inflate(R.layout.activity_main, null);
                AphidLog.d("created new view from adapter: %d", position);
            }
            NewsFragment[] newsFragment_obj = new NewsFragment[GlobalValues.titile.length];

            fragMentTra = getFragmentManager().beginTransaction();

            for (int i = 0; i < GlobalValues.titile.length; i++) {
                newsFragment_obj[i] = new NewsFragment(
                        GlobalValues.titile[i], GlobalValues.content[i]);
                AphidLog.d("Array Loc: %d", i);
            }

            fragMentTra.add(R.id.fragment_container1, newsFragment_obj[0],
                    "Fragment1");
            fragMentTra.add(R.id.fragment_container2, newsFragment_obj[1],
                    "Fragment2");
            fragMentTra.add(R.id.fragment_container3, newsFragment_obj[2],
                    "Fragment3");

            fragMentTra.commit();

            return layout;
        }
    });
    setContentView(flipView);
}
0

There are 0 answers