Java tutorial
package com.proma.Nerd; import Control.NewsControler; import Entity.News; import android.app.Activity; import android.graphics.Typeface; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; import android.widget.TextView; import com.proma.Nerd.adapter.NewsAdapter; import org.json.JSONException; import java.util.ArrayList; /* * Copyright (C) 2013 Arash Khangaldi (http://www.arashit.ir) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main_Page extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ListView listView = (ListView) findViewById(R.id.listView); NewsControler newsControler = new NewsControler(); try { ArrayList<News> newses = newsControler.getLatestNews(); NewsAdapter adapter = new NewsAdapter(getApplicationContext(), 0, newses); listView.setAdapter(adapter); } catch (JSONException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } final Typeface fontsStyle = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/byekan.ttf"); ViewGroup root = (ViewGroup) findViewById(R.id.root); setFont(root, fontsStyle); } public void setFont(ViewGroup group, Typeface font) { int count = group.getChildCount(); View v; for (int i = 0; i < count; i++) { v = group.getChildAt(i); if (v instanceof TextView || v instanceof Button || v instanceof EditText) ((TextView) v).setTypeface(font); else if (v instanceof ViewGroup) setFont((ViewGroup) v, font); } } }