0
我試圖在我的應用程序中修復帶有動態內容的列表標題。問題是我只看到標題而沒有看到內容。如果我評論了一些行,列表內容會出現,但標題不會顯示。我嘗試使用addHeader
,但它使頭不固定。修復了帶有FragmentList和動態內容的標題
我控制器
public class RadioListFragment extends ListFragment {
/** The Radios. */
private ArrayList<Radio> mRadios;
/** The Header view. */
private View mHeaderView;
/** The Radio adapter. */
private RadioAdapter mRadioAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mRadios = RadioRepo.get(getActivity()).getRadios();
mRadioAdapter = new RadioAdapter(mRadios);
setListAdapter(mRadioAdapter);
}
@TargetApi(11)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent,
Bundle savedInstanceState) {
super.onCreateView(inflater, parent, savedInstanceState);
View v = inflater.inflate(R.layout.list_header_radio, parent, false);
//mHeaderView = v.findViewById(R.id.list_header_radioTextView);
// Inflate the Header View
/*
mHeaderView = (View)getActivity()
.getLayoutInflater()
.inflate(R.layout.list_header_radio, null, false);
*/
return v;
}
private class RadioAdapter extends ArrayAdapter<Radio> {
public RadioAdapter(ArrayList<Radio> radios) {
super(getActivity(), 0, radios);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// If we weren't given a view, inflate one
if (convertView == null) {
convertView = getActivity().getLayoutInflater()
.inflate(R.layout.list_item_radio, null);
}
// Configure the view for this Radio
Radio r = getItem(position);
TextView nameTextView =
(TextView)convertView.findViewById(R.id.radio_list_item_nameTextView);
nameTextView.setText(r.getName());
return convertView;
}
}
}
list_header_radio.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/list_header_radioTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/dummy_text_view" />
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="0dp" />
</RelativeLayout>
list_item_radio.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/radio_list_item_logoImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="@string/logo" />
<TextView
android:id="@+id/radio_list_item_nameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/radio_list_item_logoImageView"
android:text="@string/radios_name" />
</RelativeLayout>
爆炸。我從來沒有想過這是很容易修復。哈哈。謝謝你的哥們。 – 2014-10-31 19:24:10
@GabrielMuñumel歡迎您:) – MohammedEAmer 2014-10-31 19:25:58