public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);``
//
//
int []imageArray={R.drawable.img1,R.drawable.img2,R.drawable.img3};
final Handler handler = new Handler();
Runnable runnable = new Runnable() {
int i=0;
public void run() {
imageView.setImageResource(imageArray[i]);
i++;
if(i>imageArray.length-1)
{
i=0;
}
handler.postDelayed(this, 50); //for interval...
}
};
handler.postDelayed(runnable, 2000); //for initial delay..
}
Sunday, May 19, 2013
How to change images on imageView after some interval
Change text size/font size of a tabhost?
You can define themes, use styles to achieve this:
First you create the theme (name:
CustomTheme
) for your Activity
in your res/styles.xml
:<style name="CustomTheme" parent="@android:style/Theme">
<item name="android:tabWidgetStyle">@style/CustomTabWidget</item>
</style>
<style name="CustomTabWidget" parent="@android:style/Widget.TabWidget">
<item name="android:textAppearance">@style/CustomTabWidgetText</item>
</style>
<style name="CustomTabWidgetText"
parent="@android:style/TextAppearance.Widget.TabWidget">
<item name="android:textSize">20sp</item>
<item name="android:textStyle">bold</item>
</style>
Then in your
androidManifest.xml
you specify the theme above for your TabActivity
orActivity
containing your TabWidget
:<activity android:name="MyTabActivity" android:theme="@style/CustomTheme">
This will serve you with the output you want (of course you should change the size and style for your preference).
Friday, May 17, 2013
Check internet connection on Android Phone
public boolean isInternetAvailable(){
//If not in activity
// ConnectivityManager cManager = (ConnectivityManager) Context.getSystemService(Context.CONNECTIVITY_SERVICE);
//if in Activity
ConnectivityManager cManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo nInfo = cManager.getActiveNetworkInfo();
if(nInfo == null)
return false;
else
return nInfo.isConnected();
}
and onclick event
if(isInternetAvailable()){
do something
}else {
Toast.makeText(getApplicationContext(), "You must be connected to the internet", Toast.LENGTH_LONG).show();
}
Thursday, May 16, 2013
List view
first xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="60dp"
ads:adUnitId="id"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
<!-- List View -->
<ListView
android:id="@+id/list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
2xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<!-- Single ListItem -->
<!-- Product Name -->
<TextView
android:id="@+id/product_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/ylistbg"
android:padding="10dip"
android:textSize="16dip"
android:textStyle="bold" />
</LinearLayout>
jav
public class ListviewOnclickExample extends Activity |
02 | { |
03 | private ListView lv1; |
04 | private String lv_arr[]={ "Android" , "iPhone" , "BlackBerry" , "AndroidPeople" , "J2ME" , "Listview" , "ArrayAdapter" , "ListItem" , "Us" , "UK" , "India" }; |
05 | @Override |
06 | public void onCreate(Bundle icicle) |
07 | { |
08 | super .onCreate(icicle); |
09 | setContentView(R.layout.main); |
10 | lv1=(ListView)findViewById(R.id.ListView01); |
11 | lv1.setAdapter( new ArrayAdapter this ,android.R.layout.slist_item, R.id.product_name, listdisplay)); |
12 |
13 | lv1.setOnItemClickListener( new OnItemClickListener() { |
14 | @Override |
15 | public void onItemClick(AdapterView a, View v, int position, long id) { |
16 | | TextView textView = (TextView)arg1.findViewById(R.id.product_name); | textt = textView.getText().toString(); |
21 | } |
22 | }); |
23 | } |
24 | } |
Subscribe to:
Posts (Atom)