This article summarizes common errors in Android development. Share it for your reference. The details are as follows:
Error 1:
Added a content to the intent, and always reports an error when calling getStringExtra to read. The code is as follows:
// back buttonButton btnBack = (Button) findViewById(.btnActivity2Back); (new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(); ("from", 2); setResult(RESULT_OK, intent); finish(); } });
The putExtra method of intent is called.
The code is read as follows:
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { TextView tview = (TextView) findViewById(.textViewResult1); if (data != null) { ("from" + ("from") + "return!"); } (requestCode, resultCode, data); }
GetStringExtra is called to read the data. An error will be reported here.
Cause of error:
When putExtra, in the code ("from", 2);, 2 is not a string, but a number. Therefore, when reading, calling getStringExtra reports an error.
If you write this: ("from", 2 + ""); there will be no problem.
Error 2:
When using simplecursoradapter for listview, I encountered the following problem.
: addView(View, LayoutParams) is not supported in AdapterView
The reason for this error is that I have an error in the layout file that contains the TextView control inside the <ListView> control. The control used to display data in the design is best placed in another layout file.
For example, the xml of my listview is:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andro android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Initialize 5000 data" /> <Button android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Read data initialization ListView" /> <ListView android: android:layout_width="fill_parent" android:layout_height="wrap_content" > </ListView> </LinearLayout>
The listview's xml is written only in the listview's xml, and the content to be displayed on each line is placed in the following:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andro android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android: android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>
Error 3:
When clicking from an item in the listview and jumping to another activity, the animation effect is wrong.
startActivity(intent); // finish(); ("mason", "gongneng ani called"); overridePendingTransition(.slide_out_right, .slide_in_left);
As in the above code. But if you call the finish() function first, the animation effect will be correct. But there is a problem at this time. After entering the new activity, press the back key and cannot return to the original activity. This is because the original activity called the finish function, which is equivalent to the user pressing the back key. It is equivalent to telling the Android system that this activity can be recycled (this activity no longer exists in the Android activity stack).
I hope this article will be helpful to everyone's Android programming design.