У меня возникла проблема с тем, что мой список не отображается в моем фрагменте. Я проверил другие связанные проблемы с StackOverflow, и я не получил ответа. Другие фрагменты работают хорошо, кроме этого фрагмента, который предназначен для отображения списка. Ниже приведен код. Фрагмент xml содержит только список.ListView in Fragment не отображается
public class FeaturedIsh extends Fragment {
ListView listview;
String title[] ={"Quote of the week","Devotional","News","Events"};
Integer titleImage[] = {R.drawable.user,R.drawable.user,R.drawable.user,R.drawable.user};
String content[] = {"The more you do, the more you are able to do, the less you do, the less you are able to do","Today's topic : Careful for nothing", "Bukola Babies won again","Two weddings this Saturday"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String title[] = {"Quote of the week","Devotional","News","Events"};
Integer titleImage[] = {R.drawable.user,R.drawable.user,R.drawable.user,R.drawable.user};
String content[] = {"The more you do, the more you are able to do, the less you do, the less you are able to do","Today's topic : Careful for nothing", "Bukola Babies won again","Two weddings this Saturday"};
Log.d("yo", "onCreate worked");
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.featuredish, container, false);
listview = (ListView)v.findViewById(R.id.feat_list_view);
Log.d("yo","inflater true");
FeaturedAdapterListNav Falnav = new FeaturedAdapterListNav(getActivity(), title, titleImage, content);
Log.d("yo","Adapter worked");
listview.setAdapter(Falnav);
Log.d("yo", "Adapter set");
return v;
}
}
Here is my adapter code
package com.example.cozasocial;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.zip.Inflater;
/**
* Created by SamuelAgbede on 5/12/2015.
*/
public class FeaturedAdapterListNav extends ArrayAdapter<String> {
Activity context;
String[] title;
Integer[] titleImage;
String[] content;
public FeaturedAdapterListNav(Activity context, String[] title, Integer[] titleImage, String[] content) {
super(context, R.layout.featured_each_row);
this.context = context;
this.title = title;
this.titleImage = titleImage;
this.content = content;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View theView = inflater.inflate(R.layout.featured_each_row, null, true);
ImageView image = (ImageView) theView.findViewById(R.id.image_featured);
TextView contents = (TextView) theView.findViewById(R.id.content);
TextView headings = (TextView) theView.findViewById(R.id.heading);
image.setImageResource(titleImage[position]);
contents.setText(content[position]);
headings.setText(title[position]);
return theView;
}
}
Может попробовать положить в макете ViewGroup например, framelayout или relativelayout, чтобы окружить ListView (вы сказали, что фрагмент xml только conta в списке). –
Кроме того, сообщение LogCat, если происходит ошибка –
Я подозреваю, что проблема связана с вашим адаптером. – tachyonflux