Get the App
SLTechnology News&Howtos  ›  Development  › 

How to display list by customizing Adapter in Android

Shulou Source: shulou.com Published: 2022-05-31 22:01:27 09月13日 Update

In this article Xiaobian for you to introduce in detail "how to customize the Adapter display list in Android", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "how to customize the Adapter display list in Android" can help you solve your doubts.

Create an activitylist.xml in the res\ layout directory. The contents are as follows:

Instead of reading the Activity list from AndroidManifest.xml, we use String Array resources. Add the following Array resources to res\ value\ string.xml:

Bezier Brush Colors Font Image Path Pen Shape Transform Bezier Pattern, Gradients Colors FontDemo, FontTypes DrawMap, JumbleImage, SeeThroughImage Polys, Paths Lines, Dashes, LineCap,LineJoin Oval, Pear, Shape2DDemo Transform

Once these resources are defined, you can use a custom Adapter in the program to display the list:

Class ActivityInfo {int iconIndex; String activityName; String activityInfo;} class ActivityInfoAdapter extends ArrayAdapter {int resource; public ActivityInfoAdapter (Context context, int resourceId, List objects) {super (context, resourceId, objects); resource=resourceId;} @ Override public View getView (int position,View ConvertView,ViewGroup parent) {LinearLayout activityInfoView; ActivityInfo activityInfo=getItem (position); String activity_Name=activityInfo.activityName String activity_Info=activityInfo.activityInfo; int iconIndex=activityInfo.iconIndex; if (ConvertView==null) {activityInfoView=new LinearLayout (getContext ()); String inflater=Context.LAYOUT_INFLATER_SERVICE; LayoutInflater vi; vi= (LayoutInflater) getContext (). GetSystemService (inflater); vi.inflate (resource, activityInfoView,true);} else {activityInfoView= (LinearLayout) ConvertView } TextView activity_NameView = (TextView) activityInfoView.findViewById (R.id.activityName); TextView activity_InfoView = (TextView) activityInfoView.findViewById (R.id.activityInfo); ImageView iconView = (ImageView) activityInfoView.findViewById (R.id.iconImage); activity_NameView.setText (activity_Name); activity_InfoView.setText (activity_Info); iconView.setImageResource (iconIndex); return activityInfoView }} public class AndroidGraphics2DTutorial extends ListActivity {private ArrayList activityInfos = new ArrayList (); private ActivityInfoAdapter aa; private final static String packgeName= "com.pstreets.graphics2d"; @ Override public void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); Resources res = getResources (); String [] activity_Names = res.getStringArray (R.array.activity_name) String [] activity_Infos = res.getStringArray (R.array.activity_info); for (int item0)

Tags: Resources content articles elements appropriateness examples keys functions ideas new knowledge more steps directories knowledge knowledge points examples programs articles categories details Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Microsoft vpn MariaDB Shulou Technology