У меня есть класс ListFragment, который должен отображать с SimpleAdapter список имен групп, включенных в массив listOfMyGroups. После компиляции ошибок нет, но нет представления, просто пустой страницы. Данные успешно загружены в listOfBookmark список с модификацией и включает в себя все загруженные имена.Android ListFragment view not display
public class MyGroupsFragment extends ListFragment {
private SimpleAdapter simpleAdapter;
private Group group;
private String valueOfNazwa;
private String valueOfId;
private SharedPreferences pref;
private SharedPreferences.Editor editor;
private Bookmark bookmark;
private List<Bookmark> listOfBookmarks;
private List<LinkedHashMap<String, String>> listOfMyGroups;
private List<String[]> helperArrayList;
private ListView listView;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_groups, container, false);
listView = (ListView) view.findViewById(android.R.id.list);
pref = PreferenceManager.getDefaultSharedPreferences(getContext());
listOfBookmarks = new ArrayList<Bookmark>();
listOfMyGroups = new ArrayList<LinkedHashMap<String, String>>();
helperArrayList = new ArrayList<String[]>();
return view;
}
@Override
public void onViewCreated (View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
init();
bookmarkToString();
initAdapter();
listView = getListView();
listView.setTextFilterEnabled(true);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(getContext(), ((TextView) view).getText(),
Toast.LENGTH_SHORT).show();
for (Map.Entry<String, String> entry : listOfMyGroups.get(position).entrySet())
valueOfNazwa = entry.getValue();
for (String[] string : helperArrayList) {
if (string[1] == valueOfNazwa)
valueOfId = string[0];
}
System.out.println(valueOfId + " - " + valueOfNazwa);
group = new Group(valueOfId, valueOfNazwa);
editor = pref.edit();
editor.putString(Constants.ID_GROUP, valueOfId);
editor.putString(Constants.NAZWA, valueOfNazwa);
editor.apply();
startActivity(new Intent(getContext(), MainActivity.class));
}
});
}
private void initAdapter(){
simpleAdapter = new SimpleAdapter(getContext(), listOfMyGroups,
android.R.layout.simple_list_item_1,
new String[] { "groups" }, new int[] { android.R.id.text1 });
listView.setAdapter(simpleAdapter);
}
public void init() {
OkHttpClient.Builder okHttpClient = new OkHttpClient.Builder();
HttpLoggingInterceptor debugger =
new HttpLoggingInterceptor()
.setLevel(HttpLoggingInterceptor.Level.BODY);
okHttpClient
.addInterceptor(debugger);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Constants.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.client(okHttpClient.build())
.build();
RequestInterface requestInterface = retrofit.create(RequestInterface.class);
String email = pref.getString(Constants.EMAIL, "");
System.out.println(email);
String id_group = pref.getString(Constants.ID_GROUP, "");
System.out.println(id_group);
String nazwa = pref.getString(Constants.NAZWA, "");
Integer id_int_group = Integer.parseInt(id_group);
Bookmark bookmark = new Bookmark(email, id_int_group, nazwa);
ServerRequest request2 = new ServerRequest();
request2.setOperation(Constants.GET_MY_GROUPS);
request2.setBookmark(bookmark);
Call<List<Bookmark>> response2 = requestInterface.operation2(request2);
response2.enqueue(new Callback<List<Bookmark>>() {
@Override
public void onResponse(Call<List<Bookmark>> call, retrofit2.Response<List<Bookmark>> response2) {
listOfBookmarks = response2.body();
}
@Override
public void onFailure(Call<List<Bookmark>> call, Throwable t) {
Log.d(Constants.TAG, "Nie zaladowano!", t);
}
});
}
public void bookmarkToString() {
for(Bookmark bookmark : listOfBookmarks) {
String nazwa = bookmark.getNazwa();
listOfMyGroups.add(createGroup("groups", nazwa));
}
}
private LinkedHashMap<String, String> createGroup(String name, String number) {
LinkedHashMap<String, String> helperGroupList = new LinkedHashMap<String, String>();
helperGroupList.put(name, number);
return helperGroupList;
}
}
Мой fragment_groups.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp" >
</ListView>
все тоже! Спасибо! :) –