Slow transition of activity: multiple "initial state of inflation" in LogCat

To create a custom font in mine ListActivity, I wrote a class CustomAdapterextending BaseAdapteraccording to this example here .

However, as described there, I wrote a method getView()as shown below:

public View getView(int position, View convertView, ViewGroup parent){
    String gameName = gameNames[position]; // gameName ist the String[] of the Custom Adapter

    TextView tv = new TextView(context);
    tv.setText(gameName);
    tv.setTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/gulim.ttf"));

    return tv;
}

It works as intended. The only thing that bothers is that it takes about three or four seconds until a list appears (and this is a very long time in this context). However, in ListActivityI installed onItemClickListeneras follows:

private void setOnItemClickListener(){
    getListView().setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int pos, long id){
            onClickEntryButton(((TextView) view).getText().toString());
        }
    });
}

private void onClickEntryButton(String gameName){
    Intent intent = new Intent(this, GameActivity.class);
    intent.putExtra("gameName", gameName);
    startActivity(intent);
    finish();
}

, ListItem, , GameActivity. Activity TextView, , SQLite. TextView. , 2-3 ( ), Activity. Activity .

- ListActivity GameActivity ListActivity -

"szipinf - "

LogCat. ? onItemClickListener getView() CustomAdapter? , - , , , , ( , SQLite 5 )?

, , .

+5
1

, !

, isuue - . 10 , , Android . , tmes.

, , .

:

private static final Hashtable<String, Typeface> cache = new Hashtable<String, Typeface>();

public static final String ASSET_PATH="assetPath";

public static Typeface getFont(Context c, String assetPath) {
    synchronized (cache) {
        if (!cache.containsKey(assetPath)) {
            try {
                Typeface t =(Typeface.createFromAsset(c.getAssets(),
                        "fonts/arial.ttf"));
                cache.put(assetPath, t);
            } catch (Exception e) {
                return null;
            }
        }
        return cache.get(assetPath);
    }
}

setTypeface

public class MyButton extends Button {

public MyButton(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

public MyButton(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public MyButton(Context context) {
    super(context);
}

@Override
public void setTypeface(Typeface tf) {

    super.setTypeface(Util.getFont(getContext(), Util.ASSET_PATH));
}

}

assetPath

: - faceManager, , .

+3

All Articles