मुझे एक सामान्य बेस एडाप्टर बनाने में दिलचस्पी है जो किसी भी listVit में किसी भी list_item पर लागू होगी। और यह list_view के लिए item_row सेट करेगा।जेनेरिक बेस एडाप्टर बनाएं?
public class GenericAdapter extends BaseAdapter
{
Context context;
ArrayList<HashMap<String, String>> list;
LayoutInflater inflater;
public GenericAdapter (Context context, ArrayList<HashMap<String, String>> list)
{
this.context = context;
this.list = list;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount()
{
return list.size();
}
@Override
public Object getItem(int position)
{
return list.get(position);
}
@Override
public long getItemId(int position)
{
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View view = convertView;
if(view == null)
{
view = inflater.inflate(R.layout.item_of_any_list, parent, false);
// i have to do something here like there may be a method which must be call
}
/*HashMap<String, String> map = list.get(position);
TextView textViewName = (TextView) view.findViewById(R.id.name);
TextView textViewDate = (TextView) view.findViewById(R.id.date);
//TextView textViewDesc = (TextView) view.findViewById(R.id.desc);
textViewName.setText(map.get("name"));
textViewDate.setText(map.get("date"));
//textViewDesc.setText(map.get("description"));
*/
return view;
}
मुझे लगता है कि मुझे एक इंटरफ़ेस बनाना है जो आइटम आइटम को अलग-अलग आइटम के लिए प्राप्त करना है। लेकिन मुझे नहीं पता कि यह संभव हो सकता है। क्या कोई मुझे बता सकता है कि मैं इसे कैसे प्राप्त कर सकता हूं।
मेरा विचार इंटरफ़ेस बनाना और जेनेरिक एडाप्टर उस इंटरफ़ेस को लागू करना है। उस इंटरफ़ेस में item_row को प्राप्त करने और सेट करने का एक तरीका है। जेनेरिक एडाप्टर को विस्तारित करने वाली कोई भी कक्षा उस विधि को लागू करनी चाहिए। यह हमें एक सामान्य एडाप्टर बनाने में मदद करेगा।
जब हम उस एडाप्टर को बढ़ाते हैं तो हमें getCount, getItem, getItemId जैसे सभी कोड लिखने की आवश्यकता नहीं है, हमें केवल एक फ़ंक्शन को ओवरराइड करना है जो फ़्लोट करने के लिए है। जो getView
अंदरअग्रिम धन्यवाद होना चाहिए
उपयोग कर सकते हैं यदि आप नहीं चाहते हैं कस्टम एडेप्टर लिखने के लिए, प्रयोग करने पर विचार एक मौजूदा लाइब्रेरी, जैसे https://github.com/ribot/easy-adapter या http://amigold.github.io/FunDapter/ – CommonsWare
यह देखें [जेनेरिक एडाप्टर] (https://github.com/sa जादशोक्री/कोर-एडाप्टर) – FarshidABZ