In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
How to do data binding Data Binding in Android development? for this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
As mentioned earlier, AndroidGraphics2DTutorial said it was derived from ListActivity. ListView,ListView and Gallery are shown in ListActivity, and Spinner has one thing in common: they are both subclasses of AdapterView. The display of AdapterView can be achieved through data binding, the data source can be an array or database records, and the data source and AdapterView are bridged by Adapter. Through Adapter,AdatperView, you can display the data source or process the user selection time, such as selecting an item in the list.
AndroidGraphics2DTutorial reads Intent-Filter in AndroidManifest.xml as
All Activity of the, displayed as a list SimpleAdapter that comes with Android API is used. Take a look at the relevant code in AndroidGraphics2DTutorial.java:
Public class AndroidGraphics2DTutorial extends ListActivity {private static final String SAMPLE_CATEGORY = "com.pstreets.graphics2d.SAMPLE_CODE"; @ Override public void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState) SetListAdapter (new SimpleAdapter (this, getData (), android.R.layout.simple_list_item_1, new String [] {"title"}, new int [] {android.R.id.text1})); getListView () .setTextFilterEnabled (true);} protected List getData () {List myData = new ArrayList (); Intent mainIntent = new Intent (Intent.ACTION_MAIN, null) MainIntent.addCategory (SAMPLE_CATEGORY); PackageManager pm = getPackageManager (); List list = pm.queryIntentActivities (mainIntent, 0); if (null = = list) return myData; String [] prefixPath; prefixPath = null; int len = list.size (); Map entries = new HashMap (); for (int I = 0; I < len) ResolveInfo info +) {ResolveInfo info = list.get (I); CharSequence labelSeq = info.loadLabel (pm); String label = labelSeq! = null? LabelSeq.toString (): info.activityInfo.name; String [] labellabelPath = label.split ("/"); String nextLabel = prefixPath = = null? LabelPath [0]: labelPath [prefixPath.length]; if ((prefixPath! = null? PrefixPath.length: 0) = labelPath.length-1) {addItem (myData, nextLabel, activityIntent (info.activityInfo.applicationInfo.packageName, info.activityInfo.name));} else {if (entries.get (nextLabel) = = null) {addItem (myData, nextLabel, browseIntent (nextLabel)); entries.put (nextLabel, true) } Collections.sort (myData, sDisplayNameComparator); return myData;} private final static Comparator sDisplayNameComparator = new Comparator () {private final Collator collator = Collator.getInstance (); public int compare (Map map1, Map map2) {return collator.compare (map1.get ("title"), map2.get ("title"));}} Protected Intent activityIntent (String pkg, String componentName) {Intent result = new Intent (); result.setClassName (pkg, componentName); return result;} protected Intent browseIntent (String path) {Intent result = new Intent (); result.setClass (this, AndroidGraphics2DTutorial.class); return result;} protected void addItem (List data, String name, Intent intent) {Map temp = new HashMap () Temp.put ("title", name); temp.put ("intent", intent); data.add (temp);} @ Override protected void onListItemClick (ListView l, View v, int position, long id) {Map map = (Map) l.getItemAtPosition (position); Intent intent = (Intent) map.get ("intent"); startActivity (intent);}}
Use data to display Layout, as shown in the above code
SetListAdapter (new SimpleAdapter (this, getData ())
Android.R.layout.simple_list_item_1, new String [] {"title"}
New int [] {android.R.id.text1}))
Specify Adapter for the ListView in ListActivity, whose data source is getData (), and getData () finds a list of all the eligible sample Activity from the Manifest.xml. Here DataSource is statically read from the file, if DataSource is an array or other data source, if the program modifies the contents of the value, then you should notifyDataSetChanged () to notify UI that the data has changed. UI refreshes the display to reflect the data changes. To put it simply, Android data binding is similar to data binding in .net WinForm and WPF.
AdapterView.OnItemClickListener () can be used to handle user selection events, and protected void onListItemClick (ListView l, View v, int position, long id) can be used for ListActivity. The implementation in AndroidGraphics2DTutorial is that if the user chooses a good Activity name, the corresponding Activity will be launched.
SimpleAdapter is used in the above code and the android.R.layout.simple_list_item_1 provided by Android is used to display the data, and Andrid also allows the use of custom Layout to display the data.
This is the answer to the question about how to do data binding Data Binding in Android development. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.