Include xml into another xml Android Example
How include layout defined in other xml file into another xml file example:
res/layout/my_layout.xml into
main.xml
res/layout/my_layout.xml into
main.xml
<include layout="@layout/my_layout" android:id="@+id/idMyLayout" />
396LW NO topic_id
AD
Další témata ....(Topics)
No resource found that matches the given name - error examples.
Exist resource file?
Is code written correctly?
Exist resource file?
Is code written correctly?
// No resource found that matches the given name (at id with value @id/myButton).
android:id="@id/myButton" // invalid id notation
android:id="@+id/myButton" // correct
// No resource found that matches the given name
// (at icon with value @drawable/icons).
// exist file icons in res/drawable folder?
<application android:icon="@drawable/icons"
//No resource found that matches the given name
//(at theme with value @style/MyThem).
<activity android:name=".Main"
android:label="@string/app_name"
android:theme="@style/MyThem">
// Exist style MyThem in styles.xml ? No only MyTheme
<style name="MyTheme" parent="android:Theme">
<item name="android:windowTitleSize">50px</item>
</style>
// exist file my_background in folder drawable ?
android:background="@drawable/my_background" //
// no resource found that matches the given name(at "label" with value "@string/app_name")
// have you the string resource defined in res/values/strings.xml ?
<string name="app_name">"My App"</string>
Fill the entire canvas with the specified color.
@Override
public void onDraw(Canvas canvas) {
canvas.drawColor(Color.GREEN);
}
File->Settings->Plugins and disable some plugins:
Use Emulator AVD with small memmory usage. For example: Virtual tablet with hight resolution have big memmory usage. Virtual phone with 240x320 resolution have small memmory usage.
Use instaed of Emulator, real device connected by USB (smarphone Samsung Galaxy or other recommended by Google whit debugable mode).
If you notice that Android Studio works slowly, consider the possibility to reduce the number of folders under antivirus protection.
Each antivirus check in your project consumes resources. You can significantly improve the performance, if you exclude certain folders from the antivirus protection.
- Google Cloud Testing
- Google Cloud Tools Core
- Google Cloud Tools for Android Studio
- CVS Integration
- Git Integration
- GitHub
- hg4idea
- Subversion Integration
Use Emulator AVD with small memmory usage. For example: Virtual tablet with hight resolution have big memmory usage. Virtual phone with 240x320 resolution have small memmory usage.
Use instaed of Emulator, real device connected by USB (smarphone Samsung Galaxy or other recommended by Google whit debugable mode).
If you notice that Android Studio works slowly, consider the possibility to reduce the number of folders under antivirus protection.
Each antivirus check in your project consumes resources. You can significantly improve the performance, if you exclude certain folders from the antivirus protection.
Difference between "@+id/” and "@id/” in Android
android:id="@+id/xxx" unique identifier of view
@id/ a reference to the unique identifier
android:id="@+id/xxx" unique identifier of view
@id/ a reference to the unique identifier
<TextView
android:id="@+id/first_element_id"
.........
/>
<TextView
android:id="@+id/second_element_id"
android:layout_below="@id/first_element_id"
..........
/>
Spinner in Android application is equivalent of ComboBox in WinApi.
Spinner get selected item to string example.
Spinner get selected item position to int example.
Main activity class MainComboBox.java
File MyOnItemSelectedListener.java
strings.xml
main.xml
Spinner get selected item to string example.
Spinner get selected item position to int example.
Main activity class MainComboBox.java
public class MainComboBox extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.countries_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
Button myButton =(Button)findViewById(R.id.button1);
myButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Spinner sp = (Spinner)findViewById(R.id.spinner);
String spinnerString = null;
spinnerString = sp.getSelectedItem().toString();
int nPos = sp.getSelectedItemPosition();
Toast.makeText(getApplicationContext(), "getSelectedItem=" + spinnerString,
Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "getSelectedItemPosition=" + nPos,
Toast.LENGTH_LONG).show();
}
});
}
}
File MyOnItemSelectedListener.java
public class MyOnItemSelectedListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
Toast.makeText(parent.getContext(), "Item is " +
parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();
}
public void onNothingSelected(AdapterView parent) {
// Do nothing.
}
}
strings.xml
<resources>
<string name="hello">Hello World, MainComboBox!</string>
<string name="app_name">ComboBox</string>
<string name="prompt">Choose a country</string>
<string-array name="countries_array">
<item>China</item>
<item>India</item>
<item>USA</item>
<item>Indonesia</item>
<item>Brazil</item>
<item>Pakistan</item>
<item>Nigeria</item>
<item>Bangladesh</item>
<item>Russia</item>
</string-array>
</resources>
main.xml
<LinearLayout xmlns:android="//schemas.android.com/apk/res/android"
android:orientation="vertical"
android:padding="10dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="@string/prompt"
/>
<Spinner
android:id="@+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="@string/prompt"
/>
<Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
Editace: 2013-01-06 10:41:45
Počet článků v kategorii: 396
Url:include-xml-into-another-xml-android-example