Próbuję zrozumieć, jak pracować z listfragmentami i niestandardowymi kartami. Więc zbudowałem ten mały przykład i zastanawiałem się, gdzie mogę ustawić dzielnik mojego listview na zerowy.Jak ustawić dzielnik (na wartość null) niestandardowego układu ListFragment
znalazłem różne sposoby: - Android: dividerHeight = "1dip" - android: dzielnik = "@ android: kolor/przezroczysty" ale dont mieć układ XML z ListView
Widziałem też coś jak listview.setDivider (null), ale nie wiem, gdzie mogę użyć tej metody w moim kodzie z powodu użycia listfragments.
Mój kod:
listview_item_row.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/ivCountry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:layout_weight="1"/>
<TextView
android:id="@+id/tvCountry"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:text="TextView"
android:layout_weight="4" />
</LinearLayout>
klasa CountryList
public class CountryList extends ListFragment {
Country[] countries2 = new Country[]
{
new Country("Netherlands"),
new Country(R.drawable.bas,"Basque Country")
};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
CountryAdapter adapter = new CountryAdapter(inflater.getContext(),R.layout.listview_item_row,countries2);
setListAdapter(adapter);
getListView().setDivider(null);
return super.onCreateView(inflater, container, savedInstanceState);
}
Moja CountryAdapter
public class CountryAdapter extends ArrayAdapter<Country>{
Context context;
int layoutResourceId;
Country[] data = null;
public CountryAdapter(Context context, int layoutResourceId, Country[] data) {
super(context,layoutResourceId,data);
this.context = context;
this.layoutResourceId = layoutResourceId;
this.data = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View row = convertView;
CountryHolder holder = null;
if (row == null) {
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent,false);
holder = new CountryHolder();
holder.imgIcon = (ImageView) row.findViewById(R.id.ivCountry);
holder.txtTitle = (TextView)row.findViewById(R.id.tvCountry);
row.setTag(holder);
} else {
holder = (CountryHolder) row.getTag();
}
Country country = data[position];
holder.txtTitle.setText(country.getTitle());
holder.imgIcon.setImageResource(country.getIcon());
return row;
}
static class CountryHolder
{
ImageView imgIcon;
TextView txtTitle;
}
Próbowałem dodanie getListView() setDivider (null) (patrz "Widok z mojego kodu treści jeszcze nie stworzył"), ale to daje mi błąd.. Jestem trochę zmieszany. Rozumiem, że muszę wskazać układ xml z listview, ale gdzie mam to zrobić? I jeśli utworzyć układ xml z listview, gdzie umieścić mój listview_item_row.xml? – Lokkio
Zamiast wywoływania 'getListView(). SetDivider (null);' w 'onCreateView', wywołaj go w' onActivityCreated' i to powinno naprawić problem. Uważam, że nigdy nie należy dotykać funkcji 'onCreateView' wewnątrz' ListFragment'. – MCeley
TAK ostatni działał: D dzięki! – Lokkio