-1

I have to create one reporting application, in which sane report format, adapter is used to generate reports layouts dynamically in view pager adapter.

 switch (index) {
    case 0:
        return new sfg();
    case 1:
        return  new Report1("1STREPORT");
    case 2:
        return new Report1("2NDREPORT");
    case 3:
        return new Report1("3RDREPORT");
    case 4:
        // Movies fragment activity
        return new Report1("4THREPORT");
    case 5:
        return new Report1("5THREPORT");
    case 6:
        return new Report1("Numbers");
    case 7:
        return new report2("6THREPORT");
    default:
        return  null;
}

In Report1 layout page contains two things, one Button and another is List View.

All the reports are displayed simultaneously.

I have to change the ListView item when I click on Button. I tried this:

public void btn_DetailedReport_Show(View view) {

    FragmentActivity myActivity= (FragmentActivity)(view.getContext());

    ListView lst1  = (ListView) view.findViewById(R.id.lst_abc);  // lst_abc is the list box Name

but lst1 is not able to call this ListView. I tried with Tag also as suggested in one example.

How can I solve this issue?

Pang
  • 9,564
  • 146
  • 81
  • 122

1 Answers1

0

If you want to access listView in fragment then it should be done like this...

In your onCreateView

View rootView = inflater.inflate(R.layout.fragment_name, container, false);
ListView lst1 = (ListView)rootView.findViewById(R.id.lst_abc);
return rootView;

you can declare ListView object as a global variable and then you can access it.

Reason behind this is you are not looking listView on you fragment you are looking in you button's view.

shreyash mashru
  • 301
  • 2
  • 9