About Baseadapter and Simpleadapter

Source: Internet
Author: User

For a long time did not get Android, really unfamiliar. The sudden whims of win10 did not say anything about the trouble for Android studio. Feel the android thing too much to learn, gradual thinking let me search the import is what

A: In simple terms is import, Java has many methods you can use directly, but is encapsulated in each package (class) Inside, you need the pilot package, in order to use the method in this package, such as sort (int[] a) This method is the int[] array in ascending order, descending array of numbers, But you have to import java.util.Arrays first, probably this means, of course, it can be imported into your own package, or you write your own method (similar to include Add header file, in order to use the function inside, you can also customize the header file)

I got simpleadapter and baseadapter this afternoon, let's write these two components.

Baseadapter:

ListView mylist;//Declares a ListView
MyList = (ListView) Findviewbyid (r.id.mylist);//Then identify the component by looking for it with myList to use this component and its class method


There are several classes of methods used by Baseadapter: GetCount (); GetItem (); Getitemid (); GetView ();
public int GetCount ()
{
The return value of the method controls the number of adapter list items
return 40;
}

Public Object getItem (int position)
{
Return null;//Set the contents of the Position list item
}
public long getitemid (int position)
{
Return position;//value as the ID of the number of list items
}
GetView (int position);//The method determines the list item component position

Override this method, and the view returned by the method will be used as a list box
@Override
Public View GetView (int position
, View Convertview, ViewGroup parent)
{
Create a linearlayout and add two components to it
LinearLayout line = new LinearLayout (mainactivity.this);
Line.setorientation (0);//Set the horizontal trend here, because the text is on the right side of the picture

ImageView image = new ImageView (mainactivity.this);//New Picture view
Image.setimageresource (R.drawable.ic_launcher);//OK picture

TextView Text = new TextView (mainactivity.this);//New Text view
Text.settext ("+" + (position +1) + "list items");//Set display text
Text.settextsize (20);//Set display text size
Text.settextcolor (color.red);//Set display text color

Line.addview (image);//Add new two components within the linear layout
Line.addview (text);
Returning LinearLayout instances
return line;
}

Complements LinearLayout linear layout knowledge. Copy
  1. Linerlayout Linear layout:
  2. This layout means that the control elements inside this are explicitly linear,
  3. We can specify how the linear layout is displayed by setorientation (int orientation).
  4. The values are: horizontal (0), VERTICAL (1). The default is horizontal. We are associated with it
  5. You can also specify it through Android:orientation in the layout file. In the same vein, the values are: horizontal,
  6. Vertical
  7. LinearLayout is a linear layout control that contains child controls that are arranged in a horizontal or vertical manner.
  8. When all widgets or other containers are arranged in a relative position, some controls will be missing or disappear when the boundary is exceeded.
  9. cannot be fully displayed. So when you're vertically aligned, there's only one widget or container for each row, no matter how wide they are.
  10. , and the horizontal arrangement is that there will be only one row high (height of the highest child control plus border height).
  11. LinearLayout keeps the widgets or container between them and aligns with each other.
  12. (relative to the right, middle, or left of a control).




Simpleadapter:

































About Baseadapter and Simpleadapter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.