I have an app with 2 tabs. Each tab has it’s respective fragment. On one of the tabs I would need to place a listview in order to receive data from stored arrays and place them as a list.
This is my code till now:
public class Frag3 extends Fragment{
ListView lv1;
ProgressDialog ShowProgress;
public ArrayList<Post> PostList = new ArrayList<Post>();
TextView tv1;
Button button1;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (container == null) {
return null;
}
View view = inflater.inflate(R.layout.tab3, container, false);
//View tv = view.findViewById(R.id.textView1);
View listView = view.findViewById(R.id.listView1);
String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
"Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
"Linux", "OS/2" };
ArrayAdapter<String> files = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1,
values);
lv1.setAdapter(files);
return view;
}
}
I’ve tried various options from different web references however none of them seemed to work. Can someone kindly guide me towards a way forward as I’m lost right now and can’t seem to understand the next steps.
The biggest issue is mis-matched variable names. You call out
lv1as a class member and set a list adatper against that, but you uselistViewto find the view. One of those needs to change.The following change ought to help out: