No resource found that matches the given name Eclipse Android xml file
AD MOB
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>
397LW NO topic_id
AD
Další témata ....(Topics)
Click Handler Android Java example source code. Open new class as activity and open URL in browser.
In layout.xml file:
In string.xml
In MainClass.java file
In layout.xml file:
android:layout_height="wrap_content" android:onClick="@string/clickHandler">
In string.xml
myClickHandler
In MainClass.java file
public void myClickHandler(View view) {
switch (view.getId()) {
// open new class as activity
case R.id.btnOpenClass: {
Intent pictureActivity = new Intent(getBaseContext(),
MyClass.class);
startActivity(pictureActivity);
}
break;
case R.id.btnAbout: {
//aboutDialogCreate();
}
break;
// open url
case R.id.btnHome: {
String url = "//android.okhelp.cz/";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}break;
}
}// end myClickHandler
// listener .. if click on button will scrolling to mTextView bottom
private OnClickListener mButtonListener = new OnClickListener() {
public void onClick(View v) {
// do something when the button is clicked
int nBottom = mTextView.getBottom();
hScrollView.scrollTo(0, nBottom);
}
};
Díl 2.
V prvním dile jsme se něco dozvěděli od XML souborech
Používáme příklad i zip porojekt z https://developer.android.com/training/basics/fragments/creating.html
V tomto díle si rozebereme záludnosti v souboru MainActivity.java.
V prvním dile jsme se něco dozvěděli od XML souborech
a taky jaké označení procesoru pro rok 2016 - Intel® VT-x, Intel® EM64T - musí mít PC pro programování v Android Studiu, tedy hlavně pro spuštění emulátoru - virtuálního telefonu, tabletu atd. jinak nebudete moci testovat aplikace na nejnovějších zařízeních, které tento emulátor umí napodobit.
Dole na stránce odkazu je uvedena minimální konfigurace PC, ale protože Android je již plnokrevný OS, který se neustále rozrůstá, tak tyto hodnoty jsou prakticky nedostatečné a je třeba osadit PC nejnovějšími komponentami.
Používáme příklad i zip porojekt z https://developer.android.com/training/basics/fragments/creating.html
V tomto díle si rozebereme záludnosti v souboru MainActivity.java.
// název balíčku
package com.example.android.fragments;
import android.os.Bundle;
// knihovny nutné pro spuštění na starších zařízeních s verzí Androidu API 4
// API verze a příslušné číslo verze Androidu jsou zde
// https://cs.wikipedia.org/wiki/Historie_verz%C3%AD_Android
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
// HeadlinesFragment je třída se seznamem položek, která díky
// OnHeadlineSelectedListener bude vracet události kliknutí na položku
// Pokud při pokusech přídáme jiný soubor se seznamem, je nutno změnit i název HeadlinesFragment
// na nový název, jinak nic neodchytíme!!!!
public class MainActivity extends FragmentActivity
implements HeadlinesFragment.OnHeadlineSelectedListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// tady se rozhoduje zda si vezme XML pro malé obrazovky, jen s jedním panelem, nebo
// velké se dvěma panely
// Rozhoduje si o tom systém sám, ale můžeme to ovlivnit a pdstrčit mu
// i dvoupanel pro testování - viz předchozí díl //android.okhelp.cz/1-fragments-tutorial-xml-czech-language/
setContentView(R.layout.news_articles);
//// VELKE OBRAZOVKY - layout-large - dual panel /////////
// pokud si systém vybere news_articles.xml z layout-large (dual panel)
// budou fragmenty automaticky naloděny do tagů fragment, kde jsou
// uvedeny absolutní cesty fragmentů!!!!
// např. fragment android:name="com.example.android.fragments.HeadlinesFragment"
// si nalodí sám fragment s linkami - položkami ListView.
// Podobně se sám obslouží při nalodění i fragment s obsahem
// fragment android:name="com.example.android.fragments.ArticleFragment"
// Tyto tagy fragment, s absolutní cestou k fragmentu,
// neumožňují výměnu fragmentu za běhu aplikace!!!!!
// Dynamickou výměnu fragmenut však umožňují kontejnery tagu FrameLayout
//// MALE OBRAZOVKY - jen jeden fragment //////
// Zkontrolujeme, který XML byl naloděn, pokud je activováno R.id.fragment_container
// značí to, že byl vybrán XML ze složky layout, kde je pouze jeden panel a do něj
// vložíme pouze fragment se seznamem, tedy HeadlinesFragment a pak po vybrání položky
// v něm otevřeme ArticleFragment.java s vypsáním obsahu článku atd.
if (findViewById(R.id.fragment_container) != null) {
// Pokud obnovujeme seznam položek vrácením se z předchozího stavu - fragmentu
// pak nepotřebujeme nic dělat a měl bychom opustit tento if, jinak
// dojde překrývání fragmentů, tedy uvídíme překryv textů a dalších elementů původního
// fragmentu fragmentem novým proto uděláme podmínku:
if (savedInstanceState != null) {
return;
}
// vytvoříme instanci HeadlinesFragment s položkami seznamu v ListView
HeadlinesFragment firstFragment = new HeadlinesFragment();
// pokud chceme vložit speciální instrukce pro start odebrané z nějakého Intent,
// odchytíme je zde a vložíme je jako argumenty. Pak je při startu fragmentu
// možno odchytit v onCreate()
firstFragment.setArguments(getIntent().getExtras());
// vložíme fragment do fragment_container FrameLayout-u
// který umožňuje výměnu fragmentů
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_container, firstFragment).commit();
}
}
// uživatel klikl na nějakou položku ze seznamu v HeadlinesFragment!
public void onArticleSelected(int position) {
// vybereme určitý článek dle pozice položky vybrané v seznamu ListView
// Provedeme kontrolu jestli je naloděn dual panel, nebo jen jednoduchý
ArticleFragment articleFrag = (ArticleFragment)
getSupportFragmentManager().findFragmentById(R.id.article_fragment);
if (articleFrag != null) {
// VELKÉ OBRAZOVKY
// protože je aktivní id R.id.article_fragment z news_articles.xml v layout-large složce
// víme, že aplikace používá dual-panel, dva fragmenty vedle sebe
// zde se volá funkce která je obsažena v třídě v souboru ArticleFragment.java
// a provede patřičné příkazy, v našem případě se
// vypíše obsah článku z třídy Ipsum.java
// sloužící jako úložiště textů přiřazených k jednotlivým
// pozicím - položkám seznamu ListView
articleFrag.updateArticleView(position);
} else {
// MALÉ OBRAZOVKY
// jen JEDEN-PANEL se zobrazuje - vybrán soubor news_articles.xml v layout složce
// musíme vyměnit fragemnty !!!!
// Vytvoříme fragment a doplníme argumenty - hodnoty, poslané např. z HeadlinesFragment.java
// jedná se nám především o pozici položky, na kterou bylo kliknuto v ListView
// tato pozice bude určující pro výběr obsahu pro ArticleFragment
ArticleFragment newFragment = new ArticleFragment();
Bundle args = new Bundle();
args.putInt(ArticleFragment.ARG_POSITION, position);
newFragment.setArguments(args);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
// Zde vyměníme původní fragment HeadlinesFragment novým fragmentem s obsahem článku atd.
// Můžeme vyměnit fragment za jiný, protože id fragment_container v layout/news_articles.xml je tagu FrameLayout
transaction.replace(R.id.fragment_container, newFragment);
// addToBackStack umožní uživateli vrátit se zpět na seznam položek v HeadlinesFragment.java
transaction.addToBackStack(null);
// celou transakci předáme ke schválení :)
transaction.commit();
}
}
}
If a button have focus, marquee will run.
Important:
android:singleLine="true"
android:ellipsize="marquee"
Optional:
android:marqueeRepeatLimit="1"
Important:
android:singleLine="true"
android:ellipsize="marquee"
Optional:
android:marqueeRepeatLimit="1"
// main.xml
<Button
android:layout_width="150dip"
android:layout_height="wrap_content"
android:text="My button with a long text for marquee as a example source code"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="1"/>
Problem: erroneous entry of id
Solution: @+id/
<RadioButton android:id="idRadio"
android:text="My radio button"/>
Solution: @+id/
<RadioButton android:id="@+id/idRadio"
android:text="My radio button"/>
public static Bitmap createBitmap (int[] colors, int offset, int stride, int width, int height, Bitmap.Config config)
public void drawBitmap (Bitmap bitmap, float left, float top, Paint paint)
public void drawBitmap (Bitmap bitmap, float left, float top, Paint paint)
// //www.apache.org/licenses/LICENSE-2.0
public class MainActivity extends Activity {
private static final int WIDTH = 50;
private static final int HEIGHT = 50;
private static final int STRIDE = 64; // must be >= WIDTH
private static int[] createColors() {
int[] colors = new int[STRIDE * HEIGHT];
for (int y = 0; y < HEIGHT; y++) {
for (int x = 0; x < WIDTH; x++) {
int r = x * 255 / (WIDTH - 1);
int g = y * 255 / (HEIGHT - 1);
int b = 255 - Math.min(r, g);
int a = Math.max(r, g);
colors[y * STRIDE + x] = (a << 24) | (r << 16) | (g << 8) | b;
}
}
return colors;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new SampleView(this));
}
private static class SampleView extends View {
// CONSTRUCTOR
public SampleView(Context context) {
super(context);
setFocusable(true);
}
@Override
protected void onDraw(Canvas canvas) {
Paint paint = new Paint();
canvas.drawColor(Color.GREEN);
int[] mColors = createColors();
int[] colors = mColors;
Bitmap bitmap = Bitmap.createBitmap(colors, 0, STRIDE, WIDTH, HEIGHT,
Bitmap.Config.RGB_565);
canvas.drawBitmap(bitmap, 50,20, paint);
}
}
}
Editace: 2014-02-15 20:47:37
Počet článků v kategorii: 397
Url:no-resource-found-that-matches-the-given-name-eclipse-android-xml-file
AD