listfragmentsとカスタムアダプタを操作する方法を理解しようとしています。だから私はこの小さな例を構築し、私はnullに私のlistviewの仕切りを設定することができたのだろうかと思っていた。ListFragmentカスタムレイアウトのDivider(nullにする)を設定する方法
私が見つけたさまざまな方法: - アンドロイド:dividerHeight = "1dip" - アンドロイド:ディバイダ= "@アンドロイド:カラー/透明" しかし、私は、リストビュー
とXMLのレイアウトを持っていけない、私も何かを見ましたlistview.setDivider(null)と似ていますが、listfragmentsを使用しているため、そのコードでどこのメソッドを使用できるか分かりません。
マイコード:
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>
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);
}
マイ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;
}
私は(ヌル)setDivider getListViewを()を追加しようとした(私のコード "まだ作成されていないコンテンツビュー" を参照)が、それは私にエラーを与えます。私はちょっと混乱している。私はリストビューでxmlレイアウトを指す必要があることを理解していますが、どこでそれを行うのですか?そして、私はリストビューでXMLレイアウトを作る場合、私はどこに私のlistview_item_row.xmlを置くのですか? – Lokkio
'onCreateView'で' getListView()。setDivider(null); 'を呼び出すのではなく、' onActivityCreated'で呼び出すと問題を解決するはずです。 'ListFragment'の中の' onCreateView'関数に決して触れないようにしました。 – MCeley
はい最後の仕事:Dありがとう! – Lokkio