Reputation: 4279
I created three fragments to show on my main activity. This is one of the three fragment activity :
public static class Fragment1 extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
String[] values=new String[]{"India", "java", "c++","Ad.Java", "Linux", "Unix"};
public Fragment1() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Create a new TextView and set its text to the fragment's section
// number argument value.
View v = inflater.inflate(R.layout.center, null);
return v;
}
}
I want to show a listView in this fragment. I tried to use this code inside onCreateView()
method :
ArrayAdapter<String> adapter=new ArrayAdapter<String>(Main.this,android.R.layout.simple_list_item_1,values);
setListAdapter(adapter);
but it shows error.. How to do this ?
Upvotes: 1
Views: 5711
Reputation: 748
this code ill help u..
String[] values=new String[]{"India", "java", "c++","Ad.Java", "Linux", "Unix"};
ListView lv;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.center, container, false);
perform(v);
return v;
}
public void perform(View v) {
lv = (ListView)v.findViewById("your view id");
ArrayAdapter<String> adapter=new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,values);
lv.setAdapter(adapter);
}
Upvotes: 6