Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize LogCat Adjustment and Test Information in Android Development

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article is to share with you about how to achieve LogCat debugging information in Android development, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

LogCat debugging information

In Window-> Show View-> Other... -> Android-> LogCat, which will show the window of LogCat. For System.out.print () and Log.d (), we can print out the information we need, such as:

System.out.print ("Hello -\ n"); Log.d ("WEI", "Hi-1 -"); Log.d ("WEI", "Hi-2 -")

In this way, we can see the relevant information in the search window of LogCat:

Effect picture

GalleyView

Galley is the meaning of a gallery. It is generally only used in picture display, and it is not commonly used.

1) Android XML file

Java Code:

Because Galley users deal with pictures, ImageView can be used to deal with item. In setting up adapter, we can see "Android Learning Notes (XIII): Activity-GridView" to inherit BaseAdapter.

2) Java source code

Java Code:

Public class Chapter7Test8 extends Activity {@ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.chapter_7_test8); / / step 1: set adapter to describe the content of item and format item as previously learned; set the click-triggered action through setOnItemClickListener (). Gallery gallery = (Gallery) findViewById (R.id.gallery); gallery.setAdapter (new ImageAdapter (this)); gallery.setOnItemClickListener (new OnItemClickListener () {public void onItemClick (AdapterView parent,View v position,long id) {Toast.makeText (Chapter7Test8.this, "" + position,Toast.LENGTH_SHORT). Show ();}});} / / step 2:adapter inherits BaseAdapter and specifically describes item. You need to create a constructor that materializes getCount (), getItem (), getItemId (), getView (). Private class ImageAdapter extends BaseAdapter {private Context mContext; private Integer [] mImageIds = {R.drawable.sample_1, R.drawable.sample_2, R.drawable.sample_3, R.drawable.sample_4, R.drawable.sample_5, R.drawable.sample_6, R.drawable.sample_7}; / / We copy the image file named drawable_sample_1 to drawable/. Public ImageAdapter (Context context) {mContext = context;} public int getCount () {return mImageIds.length;} public Object getItem (int position) {return position;} public long getItemId (int position) {return position Step 3: each item is ImageView. Render the picture through setImageResource, set the size of each item, and the display ratio. Here, we use FIT_XY to display the whole picture. If the length: width of the picture is different from the length: width of the picture, the picture may have some distortion. Public View getView (int position, View convertView, ViewGroup parent) {ImageView image = new ImageView (mContext); image.setImageResource (mImageIds [position]); image.setLayoutParams (new Gallery.LayoutParams (150100)); image.setScaleType (ImageView.ScaleType.FIT_XY); return image;}} 3) We add a xml file under res/values/ to describe the attribute format of custom widget in Java code:

Int R.styleable.XXXX [] will be added to the R.java to represent this definition, and if there are two attributes, there are two elements. In this example, by setting the properties of style, we set a property defined by android, galleryItembackground, which defines an item of gallery with a border. As follows:

Java Code:

How to get custom attributes:

Java Code:

TypedArray a = obtainStyledAttributes (R.styleable.XXX / * int [] * /); aattrId = a.getResourceId (R.styleable.XXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxiaaaaaaaaaaaaaaaget the ID of the attribute, and if it is not found, the value of defaultId is returned. A.recyle (), / / should be called after using obtainStyledAttributes (), which can be reused by the system.

In this example:

Java Code:

Public ImageAdapter (Context context) {TypedArray a = obtainStyledAttributes (R.styleable.HelloGallery); mGalleryItemBackground = a.getResourceId (R.styleable.HelloGallery_android_galleryItemBackground, 0); a.recycle ();} public View getView (int position, View convertView, ViewGroup parent) {image.setBackgroundResource (mGalleryItemBackground);} above is how to implement LogCat debugging information in Android development. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report