Tampilkan postingan dengan label layout. Tampilkan semua postingan
Tampilkan postingan dengan label layout. Tampilkan semua postingan

Delete A row in ListView with Animation

Posted by Unknown Senin, 17 Juni 2013 0 komentar
Listview is simply a group of view that displays a list of scrolling items. "Adapters" are used to insert list items to the list.By default we are able to provide only text as list items.In order to delete a row from listview, copy or download this javacode and try yourself.
Also see here :
java file :
public class SimpleListViewActivity extends Activity {

private ListView mainListView;
private ArrayAdapter<String> listAdapter;
ArrayList<String> all_rowtext = new ArrayList<String>() ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Find the ListView resource.
mainListView = (ListView) findViewById(R.id.mainListView);
all_rowtext.add("Angel");
all_rowtext.add("Mark");
all_rowtext.add("Coding");
all_rowtext.add("Playground");
all_rowtext.add("For");
all_rowtext.add("All");
all_rowtext.add("Android");
all_rowtext.add("Coderz");
// Create ArrayAdapter using the planet list.
listAdapter = new ArrayAdapter<String>(this, R.layout.singlerow,
all_rowtext);
// Set the ArrayAdapter as the ListView's adapter.
mainListView.setAdapter(listAdapter);
mainListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,
View rowView, int positon, long id) {
Toast.makeText(rowView.getContext(), "" + positon,
Toast.LENGTH_LONG).show();
removeListItem(rowView, positon);
}
});
}

protected void removeListItem(View rowView, final int positon) {
final Animation animation = AnimationUtils.loadAnimation(
SimpleListViewActivity.this, android.R.anim.slide_in_left);
rowView.startAnimation(animation);
Handler handle = new Handler();
handle.postDelayed(new Runnable() {

public void run() {
all_rowtext.remove(positon);
listAdapter.notifyDataSetChanged();
}
}, 1000);
}}

Baca Selengkapnya ....

Customized Spinners in Android

Posted by Unknown Rabu, 24 April 2013 0 komentar

See more basics on Android along with interview questions

The Android Spinner Control is definitely the equivalent of the drop-down selector . By making use of spinner control you basically obtain the capability to choose from a list without taking up all of the display screen space of a ListView.

Spinners provide a quick way to select one value from a set. In the default state, a spinner shows its currently selected value. Touching the spinner displays a dropdown menu with all other available values, from which the user can select a new one.

You can add a spinner to your layout with the Spinner object. You should usually do so in your xml layout with a  <spinner>  element. For example:
 <Spinner
    android:id="@+id/myspinner"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

Here we are going to deal with Customized Spinners.Here we go with java code samples.

in java file:
public class Custom_spinner extends Activity {
String[] data1 = { "Java", "Android","Blackberry", "Apple", "Windows" };

String[] data2 = { "Developed by Sun Microsystems", "Android is a Linux-based operating system",
"Designed and marketed by Research In Motion Limited ","Designed and marketed by Apple Inc"
,"developed, marketed, and sold by Microsoft."};

Integer[] images = { R.drawable.java, R.drawable.android,
R.drawable.blackberry, R.drawable.apple, R.drawable.windows };

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.custom_spinner);
Spinner mySpinner = (Spinner) findViewById(R.id.spinner1);
mySpinner.setAdapter(new MyAdapter(this, R.layout.cus_row, data1));
}

public class MyAdapter extends ArrayAdapter<String> {

public MyAdapter(Context context, int textViewResourceId,
String[] objects) {
super(context, textViewResourceId, objects);
// TODO Auto-generated constructor stub
}

@Override
public View getDropDownView(int position, View convertView,
ViewGroup parent) {
return getCustomView(position, convertView, parent);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
return getCustomView(position, convertView, parent);
}

public View getCustomView(int position, View convertView,
ViewGroup parent) {

LayoutInflater inflater = getLayoutInflater();//inflate xml for each row
View row = inflater.inflate(R.layout.cus_row, parent, false);
TextView label = (TextView) row.findViewById(R.id.textView1);
label.setText(data1[position]);

TextView sub = (TextView) row.findViewById(R.id.textView2);
sub.setText(data2[position]);

ImageView icon = (ImageView) row.findViewById(R.id.imageView1);
icon.setImageResource(images[position]);

return row;
} }}

in custom_spinner.xml (main xml file) :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp" >
<Spinner

android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:background="@drawable/purple"
>
</Spinner>
</RelativeLayout>
in cus_row.xml (inflated xml file) :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="3dip" >

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" >
</ImageView>
</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="70dp" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold" >
</TextView>

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TextView>
</LinearLayout>

</RelativeLayout>
@drawable/purple.xml :

















Baca Selengkapnya ....

Get Id of inflated xml in ANDROID

Posted by Unknown Selasa, 19 Maret 2013 0 komentar
How to inflate an xml see my previous post.
Suppose we have button in the inflated xml we can get the id like this:
 Button b1= (Button) v1.findViewById(R.id.button1); 
//where v1 is the View

Baca Selengkapnya ....

How to enable and disable Wifi in ANDROID?

Posted by Unknown Rabu, 13 Maret 2013 0 komentar

WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(enabled);

Baca Selengkapnya ....

Using external font in ANDROID

Posted by Unknown Selasa, 12 Maret 2013 0 komentar
    

TextView text =(TextView) findViewById(R.id.textview);
Typeface face;
face = Typeface.createFromAsset(getAssets(), "AMAZB.TTF");
text.setTypeface(face);
text.setTextSize(30);
text.setTextColor(Color.WHITE);

Baca Selengkapnya ....

Merge two layouts in xml

Posted by Unknown 0 komentar
In any one of the xml include the other xml like this :

<include layout="@layout/newxmlname"/>

Baca Selengkapnya ....

Expandable ListView in ANDROID

Posted by Unknown Jumat, 01 Maret 2013 0 komentar
java.class

public class Expandablelistview extends ExpandableListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.expandablelistview);
SimpleExpandableListAdapter expListAdapter =
new SimpleExpandableListAdapter(
this,
createGroupList(),
R.layout.group_row,
new String[] { "Item" },
new int[] { R.id.row_name },
createChildList(),
R.layout.child_row,
new String[] {"Sub Item"},
new int[] { R.id.grp_child});
setListAdapter( expListAdapter );
}

// hash map for row

private List createGroupList() {
ArrayList result = new ArrayList();
for (int i = 0; i < 15; ++i) { // 15 groups........
HashMap m = new HashMap();
m.put("Item", "Item " + i); // the key and it's value.
result.add(m);
}
return (List) result;
}

/* creatin the HashMap for the children */

private List createChildList() {
ArrayList result = new ArrayList();
for (int i = 0; i < 15; ++i) {
ArrayList secList = new ArrayList();
for (int n = 0; n < 3; n++)
{
HashMap child = new HashMap();
child.put("Sub Item", "Sub Item " + n);
secList.add(child);
}
result.add(secList);
}
return result;
}


public void onGroupExpand(int groupPosition) {
try
{
System.out.println("Group exapanding
Listener => groupPosition = "
+ groupPosition);
} catch (Exception e) {
System.out.println(" groupPosition Errrr +++ "
+ e.getMessage());
} } }

expandablelistview.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ExpandableListView android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bkg"/>

<TextView android:id="@+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="No items"/>
</LinearLayout>

child_row.xml:
 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
< TextView android:id="@+id/grp_child"
android:paddingLeft="50px"
android:focusable="false"
android:textSize="14px"
android:textStyle="normal"
android:layout_width="150px"
android:layout_height="wrap_content"/>
</LinearLayout>
group_row.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<TextView android:id="@+id/row_name"
android:paddingLeft="50px"
android:textSize="20px"
android:textStyle="normal"
android:layout_width="320px"
android:layout_height="wrap_content"/>

</LinearLayout>


Baca Selengkapnya ....

Android – Bullets in ListView

Posted by Unknown Senin, 18 Februari 2013 0 komentar
main.xml :
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="10dp">

<ListView
android:id="@+id/listView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:listSelector="@android:color/transparent"
android:divider="@null"/>
</LinearLayout>
create a bullet.xml in drawable folder:
<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size
android:height="6dp"
android:width="6dp"/>
<solid android:color="#FF00F0"/>
</shape>
list_item.xml for creating custom listview:
<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/itemText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/bullet"
android:drawablePadding="8dp"
android:padding="5dp"
android:text="List Item"
android:textSize="20sp"/>
BulletListViewActivity.java
public class BulletedListViewActivity extends Activity {
/** Called when the activity is first created. */
ArrayList<string> listCountry;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
prepareList();
ListView listView = (ListView)findViewById(R.id.listView);
listView.setAdapter(new ArrayAdapter<string>(
this, R.layout.list_item, listCountry));
}
public void prepareList()
{
listCountry = new ArrayList<string>();
listCountry.add("India");
listCountry.add("Brazil");
listCountry.add("Canada");
listCountry.add("China");
listCountry.add("France");
listCountry.add("Germany");
listCountry.add("Iran");
listCountry.add("Italy");
listCountry.add("Japan");
listCountry.add("Korea");
listCountry.add("Mexico");
listCountry.add("Netherlands");
listCountry.add("Portugal");
listCountry.add("Russia");
listCountry.add("Saudi Arabia");
listCountry.add("Spain");
listCountry.add("Turkey");
listCountry.add("United Kingdom");
listCountry.add("United States");
}}

                

Baca Selengkapnya ....

How to write interfaces in java or Android?

Posted by Unknown 0 komentar
what is an Interface?
An interface is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface.
An interface is not a class. Writing an interface is similar to writing a class, but they are two different concepts. A class describes the attributes and behaviors of an object. An interface contains behaviors that a class implements.
Unless the class that implements the interface is abstract, all the methods of the interface need to be defined in the class.

MainActivity.java
public class MainActivity extends Activity implements Interface {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public void testFunctionOne() {
System.out.println("Print from testFunctionOne in the Interface");
}
@Override
public void testFunctionTwo() {
System.out.println("Print from testFunctionTwo in the Interface");
}}
in Interface.java
public interface Interface  {    
void testFunctionOne();
void testFunctionTwo(); }

Baca Selengkapnya ....

Using DialogFragments in Android

Posted by Unknown Minggu, 17 Februari 2013 0 komentar
MainActivity.java :
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager fm = getSupportFragmentManager();
dialogfragment testDialog = new dialogfragment();
testDialog.setRetainInstance(true);
testDialog.show(fm, "fragment_name");
}}
Dialogfragment.java :
public class Dialogfragment extends DialogFragment {    
public void TestDialog() {
// Empty constructor required for DialogFragment
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dialog, container);
return view;
} }
dialog.xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/edit_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/lbl_your_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello from Mark's Playground, DialogFragment Demo"/>
</LinearLayout>

  


Baca Selengkapnya ....

Fragmentation In Android

Posted by Unknown 0 komentar

See more basics on Android along with interview questions

Fragments are a portion of an Activity:
Load a fragment Activity to call a fragment :
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
} }
activity_main :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<fragment
android:id="@+id/titles"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1"
class="com.example.googlefragment.TitlesFragment"/>
//calls the fragment
</LinearLayout>
TitlesFragment :
public class TitlesFragment extends android.support.v4.app.ListFragment {
boolean mDualPane;
int mCurCheckPosition = 0;
String titles[] = { "Item one", "Item two", "Item three" };
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Populate list with our static array of titles.setListAdapter(new ArrayAdapter(getActivity(),
android.R.layout.simple_dropdown_item_1line,titles));

// Check to see if we have a frame in which to embed the details
// fragment directly in the containing UI.
View detailsFrame = getActivity().findViewById(R.id.details);
mDualPane = detailsFrame != null && detailsFrame.getVisibility() == View.VISIBLE;
if (savedInstanceState != null) {
// Restore last state for checked position.
mCurCheckPosition = savedInstanceState.getInt("curChoice", 0);
}
if (mDualPane) {
// In dual-pane mode, the list view highlights the selected item.
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
// Make sure our UI is in the correct state.
showDetails(mCurCheckPosition);
}else
{
System.out.println("NOT DUAL");
} }

@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt("curChoice", mCurCheckPosition);
}
@Override
public void onListItemClick(ListView l, View v,int position,long id) {
showDetails(position);
}
void showDetails(int index) {
mCurCheckPosition = index;
if (mDualPane) {
// We can display everything in-place with fragments,so update
// the list to highlight the selected item and show the data.
getListView().setItemChecked(index, true);
// Check what fragment is currently shown,replace if needed.
DetailsFragment details = (DetailsFragment)
getFragmentManager().findFragmentById(R.id.details);
if (details == null || details.getShownIndex()!=index) {
// Make new fragment to show this selection.
details = DetailsFragment.newInstance(index);
// Execute a transaction, replacing any existing fragment
// with this one inside the frame.
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.details, details);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.commit();
}
} else {
// Otherwise we need to launch a new activity to display
// the dialog fragment with selected text.
Intent intent = new Intent();
intent.setClass(getActivity(),DetailsActivity.class);
intent.putExtra("index", index);
startActivity(intent);
} }}
DetailsActivity :
public class DetailsActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
setContentView(R.layout.details_lay);
System.out.println("LANNNNNNNNNNN");
return;
}
if (savedInstanceState == null) {
System.out.println("LLLLLLLLLLL");
Fragment details = new DetailsFragment();
details.setArguments(getIntent().getExtras());
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, details).commit();

} } }
details_lay:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/details"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1"
class="com.example.googlefragment.DetailsFragment"/>
</LinearLayout>
DetailsFragment :
public class DetailsFragment extends Fragment {
static int i = 0;
public static DetailsFragment newInstance(int index) {
DetailsFragment f = new DetailsFragment();
// Supply index input as an argument.
Bundle args = new Bundle();
args.putInt("index", index);
i = index;
f.setArguments(args);
return f;
}
public int getShownIndex() {
return getArguments().getInt("index", 0);
}
@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
if (container == null) {
return null;
}
WebView wv = new WebView(getActivity());
wv.loadData("Hello " + i, "text/html", "utf-8");
return wv;
} }
NOTE: Put layout under two separate folder for layout and portrait.


Baca Selengkapnya ....

Spinners in Android

Posted by Unknown Kamis, 24 Januari 2013 0 komentar
The Android Spinner Control is definitely the equivalent of the drop-down selector . By making use of spinner control you basically obtain the capability to choose from a list without taking up all of the display screen space of a ListView.

Spinners provide a quick way to select one value from a set. In the default state, a spinner shows its currently selected value. Touching the spinner displays a dropdown menu with all other available values, from which the user can select a new one.

You can add a spinner to your layout with the Spinner object. You should usually do so in your xml layout with a  <spinner>  element.
For example:
 <Spinner
   
        android:id="@+id/myspinner"   
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

Here we go with java source code:
in java file:
 
public class simplespinnersactivity extends Activity implements OnItemSelectedListener {
TextView selection;
String[] items = { "this", "is", "a","really","a" "simple","list", "in", "android", "ok" };

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
selection = (TextView) findViewById(R.id.selection);
Spinner spin = (Spinner) findViewById(R.id.spinner);
spin.setOnItemSelectedListener(this);
ArrayAdapter aa = new ArrayAdapter(this,android.R.layout.simple_spinner_item,items);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(aa);
}
public void onItemSelected(AdapterView parent, View v,int position,long id)
{
selection.setText(items[position]);
}
public void onNothingSelected(AdapterView parent)
{
selection.setText("");
}
}

in xml file:
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/selection"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"/>

<Spinner
android:id="@+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop = "true">

</Spinner>
</LinearLayout>

Baca Selengkapnya ....

Blinking TextView - Two Methods

Posted by Unknown Rabu, 23 Januari 2013 0 komentar
METHOD 1

private void blink(){
final Handler handler = new Handler();
new Thread(new Runnable() {
public void run() {
int timeToBlink = 600; //in milissegunds
try
{
Thread.sleep(timeToBlink);
}catch (Exception e)
{

}handler.post(new Runnable()
{
public void run()
{
TextView txt = (TextView)findViewById(R.id.usage);
if(txt.getVisibility() == View.VISIBLE)
{
txt.setVisibility(View.INVISIBLE);
}else
{
txt.setVisibility(View.VISIBLE);
}
blink();
}
});
}
}).start();
}
METHOD 2

TextView myText = (TextView) findViewById(R.id.usage );
Animation anim = new AlphaAnimation(0.0f, 1.0f);
anim.setDuration(50);
//You can manage the time of the blink with this parameter
anim.setStartOffset(20);
anim.setRepeatMode(Animation.REVERSE);
anim.setRepeatCount(Animation.INFINITE);
myText.startAnimation(anim);

Baca Selengkapnya ....

Customize The Title Bar in Android

Posted by Unknown 0 komentar
xml for custom title bar:

< ?xml version="1.0" encoding="utf-8"?>
< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/titlebar>
< TextView
style="@style/MyRedTextAppearance"
android:padding="7dp"
android:id="@+id/txtvew_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#FFFFFF"
android:textSize="20dp"
android:textStyle="bold"
android:gravity="center"/>
< /LinearLayout>
main.xml:
Include the above xml to the main xml as given below...

< RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/redbg" >
< include
android:id="@+id/head"
layout="@layout/titlebaar" />
< LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/head"
android:padding="5dp" >
--- ---- --- ---- --- --- -- --
--- --- ---- --- --- --- --- --
< /LinearLayout>
< /RelativeLayout>
in java class:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.show_image);

TextView t1 = (TextView) findViewById(R.id.txtvew_title);
t1.setText("Custom Title Bar");
t1.setTextColor(Color.RED);
}

Baca Selengkapnya ....

How to use RadioButtonGroup in Android?

Posted by Unknown 0 komentar
in xml page:

< ?xml version="1.0" encoding="utf-8"?>
< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
< TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Which company do you like the most?"
android:textSize="25dp"
android:textStyle="bold" />
< RadioGroup
android:id="@+id/menu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:checkedButton="@+id/lunch"
android:orientation="vertical" >
< RadioButton
android:id="@+id/google"
android:checked="true"
android:text="Google" />
< RadioButton
android:id="@+id/ms"
android:text="Microsoft" />
< RadioButton
android:id="@+id/apple"
android:text="Apple" />
< RadioButton
android:id="@+id/nokia"
android:text="Nokia" />
< RadioButton
android:id="@+id/samsung"
android:text="Samsung" />
< /RadioGroup>
< TextView
android:id="@+id/choice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text=""
android:textSize="25dp" />
< Button
android:id="@+id/clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear CheckBoxes" />
< /LinearLayout>
in Java Class:

public class Page Flipping extends Activity implements
RadioGroup.OnCheckedChangeListener, View.OnClickListener {

private TextView mChoice;
private RadioGroup mRadioGroup;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_page_flipping);
mRadioGroup = (RadioGroup) findViewById(R.id.menu);
// test listening to checked change events
mRadioGroup.setOnCheckedChangeListener(this);
mChoice = (TextView) findViewById(R.id.choice);
// test clearing the selection
Button clearButton = (Button) findViewById(R.id.clear);
clearButton.setOnClickListener(this);
}

public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.google) {
mChoice.setText("Selected Google");
}
if (checkedId == R.id.ms) {
mChoice.setText("Selected Microsoft");
}
if (checkedId == R.id.apple) {
mChoice.setText("Selected Apple");
}
if (checkedId == R.id.nokia) {
mChoice.setText("Selected Nokia");
}
if (checkedId == R.id.samsung) {
mChoice.setText("Selected Samsung");
}
}

public void onClick(View v) {
mRadioGroup.clearCheck();
}
}

Baca Selengkapnya ....

Option Menu in Android

Posted by Unknown Kamis, 17 Januari 2013 0 komentar
menu.xml :

< ?xml version="1.0" encoding="utf-8"?>
< menu xmlns:android="http://schemas.android.com/apk/res/android">
< item android:id="@+id/item1" android:title="Option 1"
android:icon="@android:drawable/ic_menu_compass"/>
< item android:id="@+id/item2" android:title="Option 2"
android:icon="@android:drawable/ic_menu_week"/>
< item android:id="@+id/item3" android:title="Option 3"
android:icon="@android:drawable/ic_menu_call"/>
< item android:id="@+id/item4" android:title="Option 4"
android:icon="@android:drawable/ic_menu_zoom"/>
< /menu>
Click on the menu button to open this menu
in java class :

public class OptionMenuActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
MenuInflater inflater=getMenuInflater();
inflater.inflate(R.layout.menu,menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
if(item.getItemId()==R.id.item1)
{
Log.d("option","Option 1 was clicked");
}
if(item.getItemId()==R.id.item2)
{
System.out.println("item2 selected");
}
if(item.getItemId()==R.id.item3)
{
System.out.println("item3 selected");
}
if(item.getItemId()==R.id.item4)
{
System.out.println("item4 selected");
}
return super.onOptionsItemSelected(item);
}
}

Baca Selengkapnya ....

Custom AlertBox in Android

Posted by Unknown Rabu, 16 Januari 2013 0 komentar
in main.xml file:

< ?xml version="1.0" encoding="utf-8"?>
< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

< Button
android:id="@+id/button1"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Button" />

< /LinearLayout>
in dialog.xml :(xml for custom dialog box) :

< ?xml version="1.0" encoding="utf-8"?>
< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

< ImageView
android:id="@+id/imageView1"
android:layout_width="210dp"
android:layout_height="232dp"
android:padding="40dp"
android:src="@drawable/flower" />

< TextView
android:id="@+id/textView1"
android:layout_width="147dp"
android:layout_height="wrap_content"
android:text="This is a flower"
android:textSize="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"/>

< /LinearLayout>
in java file:

Button b= (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Dialog d=new Dialog(CustomdialogActivity.this);
d.setContentView(R.layout.dialog);
d.setTitle("This is important");
d.show();
}
});


Baca Selengkapnya ....

Vertical Text in Xml in Android

Posted by Unknown Selasa, 15 Januari 2013 0 komentar
A simple way is to insert a \n after each character, and make sure that the the height is set to fill_parent.

< TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="h\ne\nl\nl\no\n w\no\nr\nl\nd" />

Baca Selengkapnya ....

Frame by Frame Animation in Android

Posted by Unknown 0 komentar
Call a new xml file which includes the frames that are to be loaded:

< ?xml version="1.0" encoding="utf-8"?>
< animation-list android:oneshot="false" xmlns:android="http://schemas.android.com/apk/res/android">
< item android:drawable="@drawable/frame_above95_1" android:duration="30"/>
< item android:drawable="@drawable/frame_above95_2" android:duration="30"/>
< item android:drawable="@drawable/frame_above95_3" android:duration="30"/>
< item android:drawable="@drawable/frame_above95_4" android:duration="30"/>
< item android:drawable="@drawable/frame_above95_5" android:duration="30"/>
< item android:drawable="@drawable/frame_above95_6" android:duration="30"/>
< item android:drawable="@drawable/frame_above95_7" android:duration="30"/>
< item android:drawable="@drawable/frame_above95_8" android:duration="30"/>
< item android:drawable="@drawable/frame_above95_9" android:duration="30"/>
< item android:drawable="@drawable/frame_above95_10" android:duration="30"/>
< item android:drawable="@drawable/frame_above95_11" android:duration="30"/>
< item android:drawable="@drawable/frame_above95_12" android:duration="30"/>
< item android:drawable="@drawable/frame_above95_13" android:duration="30"/>
< item android:drawable="@drawable/frame_above95_14" android:duration="30"/>
< item android:drawable="@drawable/frame_above95_15" android:duration="30"/>
< item android:drawable="@drawable/frame_above95_16" android:duration="30"/>
< item android:drawable="@drawable/frame_above95_17" android:duration="30"/>
< item android:drawable="@drawable/frame_above95_18" android:duration="30"/>
< /animation-list>
in java file:

img1.setBackgroundResource(R.layout.animation_above95);
AnimationDrawable anim=(AnimationDrawable)img1.getBackground();
anim.start();

Baca Selengkapnya ....

Read from Asset and Write to a TextView

Posted by Unknown Jumat, 11 Januari 2013 0 komentar
Code for reading from a text file in asset folder to a textview:


public class Readfile extends Activity {
String path;
ArrayList data = new ArrayList();

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
path = getResources().getString(R.string.directory1);
String[] data1 = null;
AssetManager am = getResources().getAssets();
try {
data1 = am.list(path);
} catch (Exception e) {
}
for (String name : data1) {
data.add(name);
}
Readoperation();
}
public void Readoperation() {
// TODO Auto-generated method stub
TextView txt = (TextView) findViewById(R.id.text);
try {
path=getResources().getString(R.string.directory1) +"/"+data.get(2);
InputStream stream = getAssets().open(path);
int size = stream.available();
byte[] buffer = new byte[size];
stream.read(buffer);
stream.close();
txt.setText(Html.fromHtml(new String(buffer).trim()));
}
catch (IOException e) {
}}

Baca Selengkapnya ....
« Postingan Lama Beranda
Trik SEO Terbaru support Online Shop Baju Wanita - Original design by Bamz | Copyright of android populer.