6

मैं समझने की कोशिश कर रहा हूं कि सूचीफ्रेम और कस्टम एडाप्टर के साथ कैसे काम करना है। तो मैं इस छोटे से उदाहरण का निर्माण करता हूं और मैं सोच रहा था कि मैं अपनी सूचीदृश्य के विभाजक को शून्य पर सेट कर सकता हूं। dividerHeight = "1dip" - एंड्रॉयड: - एंड्रॉयड :लिस्टफ्रैगमेंट कस्टम लेआउट के डिवाइडर (शून्य) को कैसे सेट करें

मैं अलग अलग तरीकों से पाया विभक्त = "@ एंड्रॉयड: रंग/पारदर्शी" लेकिन मुझे नहीं सूचीदृश्य साथ एक एक्सएमएल लेआउट

मैं भी कुछ देखा listview.setDivider (शून्य) की तरह, लेकिन मुझे नहीं पता कि मैं सूची कोड के उपयोग के कारण अपने कोड में उस विधि का उपयोग कहां कर सकता हूं।

मेरे कोड:

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; 
} 

उत्तर

18

तुम हमेशा onCreateView पर एक दृश्य के वापस लौट कर ListFragment के लिए एक कस्टम दृश्य सेट कर सकते हैं() लेकिन आपकोमें समझाए गए "@ id/android: list" के साथ इसमें एक सूची दृश्य होना चाहिए।

अपने एक्सएमएल में आप android:divider="@null" कर सकते हैं या यदि आप वास्तव में अपनी सूचीफ्रैगमेंट कोड getListView().setDivider(null); (एक्टिविटीक्रेटेड() विधि में) में ऐसा करना चाहते हैं।

+0

मैं getListView() जोड़ने की कोशिश की setDivider (शून्य) (मेरे कोड "अभी तक नहीं बनाया सामग्री दृश्य" देखें) लेकिन यह है कि मुझे एक त्रुटि देता है।। मै थोड़ा अस्पष्ट हूँ। मैं समझता हूं कि मुझे एक सूची दृश्य के साथ एक एक्सएमएल लेआउट को इंगित करने की आवश्यकता है, लेकिन मैं यह कहां कर सकता हूं? और यदि मैं एक सूचीदृश्य के साथ एक एक्सएमएल लेआउट बना देता हूं, तो मैं अपनी listview_item_row.xml कहां डालूं? – Lokkio

+3

'getListView()। SetDivider (null) को कॉल करने के बजाय; 'onCreateView' में, इसे' AtctivityCreated' 'में कॉल करें और इससे समस्या ठीक होनी चाहिए। मैं इसे 'ListFragment'' के अंदर 'ऑनक्रेट व्यू' फ़ंक्शन को कभी भी छूने का एक बिंदु बना देता हूं। – MCeley

+0

हाँ आखिरी काम किया: डी धन्यवाद! – Lokkio

3

अंदर onCreateView उपयोग:

getListView().setDivider(null);

+0

आप कोष्ठक भूल गए? – Lokkio

+0

क्या ब्रांड्स? – Rawkode

+0

getListView()? – Lokkio