Thursday, 1 January 2015

IPhone mobile application

Yes, as per introduction to mobile applications, to develop iphone application requirements are

     1. Mac operating system and XCode editior
     2. Objective-c programming knowledge.
     3. Swift is another simplified programming language on xcode editior.


Mobile Applications Lead

Yes, this year i hope, will publish samplified articles on mobile development on iphone, android with native coding. and cross platform development.

Mobileappslead : Wish you happy new year 2015 followers.

Saturday, 11 October 2014

ListView OnItemClickListner

Yes, in this article we did two things,

1. Adding Items to ListView
2. Register ListView to event(OnItemClickListner) to find which item is clicked.



Adding Items to ListView

In Add(onclick) adding items to Listview at runtime using ArrayList, ArrayAdapter of string type.

ArrayAdapter will take String[] as a parameter as a source. so i taken arraylist(al). arraylist can take string item.

String item=edt.getText().toString().trim();
al.add(item); then adapter will be updated automatically using predefined event

adapter.notifyDataSetChanged();   at onCreate method it taken al as input/source.

adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,al);

Register OnItemClickListener

import android.widget.AdapterView.OnItemClickListener;

MainActivity implement OnItemClickListerner also. which fires whenever an item is clicked on ListView.

this event has 4 parameters.

onItemClick(AdapterView<?> parent, View view, int position,long id);

parent  :  is Listview,Gridview,spinner,...ect who currently binding Adapterview data.

as well we can check (Listview1, Listview2..also)

view :   view with in the AdapterView.  

position :  item position in the adapterview.

args3   : the Row id of the item was clicked.

ListView Databinding, add remove items

yes, we know Listview a component to bind list of items, if items are more it will show items in scrollview behaviour.

in this demo: we added 2 string-array files(awords,bwords). awords added at design time, and bwords are added at runtime(button click--Bind items).

blistwords items are,we can't get at class declaration time because bwords are not available resources are loaded. so added that onclick event.

public class MainActivity extends Activity implements OnClickListener,OnItemClickListener
{
    Button addbtn,delbtn;
    ListView listview;
    EditText edt;
    ArrayList<String> al;
    ArrayAdapter<String> arrayadapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edt=(EditText)findViewById(R.id.editText1);
listview=(ListView)findViewById(R.id.listView1);
addbtn=(Button)findViewById(R.id.button1);
delbtn=(Button)findViewById(R.id.button2);
al=new ArrayList<String>();
arrayadapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,al);
listview.setAdapter(arrayadapter);
addbtn.setOnClickListener(this);
delbtn.setOnClickListener(this);
listview.setOnItemClickListener(this);
}
Add and remove items

public void onClick(View v)
{
if(v==addbtn)
{
String item=edt.getText().toString().trim();
if(item.length()>0)
{
al.add(item);
arrayadapter.notifyDataSetChanged();
edt.setText("");
edt.requestFocus();
}
}
if(v==delbtn)
{
String item=edt.getText().toString().trim();
if(item.length()>0)
{
al.remove(item);
arrayadapter.notifyDataSetChanged();
edt.setText("");
edt.requestFocus();
}
}
}
AdapterView event : this event supports of listview, spinner...ect

public void onItemClick(AdapterView<?> parent, View view, int position,long id)
{
TextView tv=(TextView)view;
String item=tv.getText().toString();
edt.setText(item);
}

Sunday, 28 September 2014

AutoCompleteTextView in android

yes, AutocompleteTextview is a view component which is not available in our Palette controls. directly we have to write in our layout .xml file. inside Relatielayout of activity_main.xml

 <AutoCompleteTextView
        android:id="@+id/AutoCompleteView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
         android:completionThreshold="3"
 </AutoCompleteTextView>

here we given threshold at design time itself,  or runtime also set this threshold value.






 AutoCompleteTextview : is an EditText with autocomplete funcationality.  this is achived using Adapter.adapter acts a bridge between edittext and underlaying data/values. adapter is responsible for view each item in that dataset.

1st way i utilized predefined   android.R.layout.simple_list_item_1  Style for showing items in Autocompletetextview.

2nd way i designed one layout file as Root element is TextView---mystyle.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
     android:textColor="#f00"--------->red color so that values(india,indonisa) showing in red color.
    android:textSize="16sp"
    android:padding="12dp" >
</TextView>

Externalizing values :    it defines a file with resources as an string-array named as countries.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
      <string-array name="country">
        <item>India</item>
        <item>Indonesia</item>
        <item>Iran</item>
        <item>Iraq</item>
        <item>Ireland</item>
        <item>Poland</item>
        <item>Pakistan</item>
        <item>Peru</item>      
    </string-array>
</resources>

Thursday, 25 September 2014

Resources in Android application

yes, in andriod application we have nice project structure to organize the project with the help of speration/extranalization as resources in the project in res folder.

based on resource type : strings, images,color, menu,styles ..has their respective folders like Values,Drawable,Colors,Menu...are predefined structures should maintain. buf finally we called all of them as resources.



as well extranalizating resoures and alternative resources are supports specific
device configurations,
different languages,
based screen sizes...ect.

ColorStateList is a list  resouce :

    clolorstatelist is an object we can define as an mycolor.xml that can apply a color to a viewobject, so that depending on the state/behaviour of the view object the color gets changed on the view componet.

we can  apply color to the view component in 2 ways

1. design time                 2.runtime

any of the above we need to create an xml which is type Color List.

select Android Project(ColorsProject)--New --Other--New android xml file----

Type of Resouce  : color List
File                       : mycolors
Root Element       : selector

then as mycolors.xml is created with selector as root element. now we added two colors with two behaviours(pressed,checked).

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:color="#0f0"/>
    <item android:state_checked="true" android:color="#00f" />
    <item android:color="#f00"/>

</selector>

at design time:

 <Button
        android:id="@+id/button1"
        android:textColor="@color/mycolors"></Button>



at runtime/programatic time:

public class MainActivity extends Activity implements OnClickListener {

Button b2,b3;
@Override
protected void onCreate(Bundle savedInstanceState)
       {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b2=(Button)findViewById(R.id.button2);
b2.setOnClickListener(this);

               b3=(Button)findViewById(R.id.button3);
b3.setOnClickListener(this);

}
@Override
public void onClick(View v)
    {
      if(v==b2)
b2.setTextColor(getResources().getColor(R.color.mycolors));
else
b3.setTextColor(getResources().getColorStateList(R.color.mycolors));

}



we have 2 more options based on class, and configuration also. for apply resouce to view object.


Monday, 15 September 2014

Linking Activities using Intents,Passing data between 2 Activities

Yes, In andriod we have Intents to pass data from one activity to another activity. intent is available package  android.content.Intent.

design First Activity/Main_activity.which bydefault specified in andriod manifest file.




& Second Activity and Specify this in androidManifest.xml
then speciy in manifest file

    <activity android:name="com.exampleintents.intentsproject.SecondActivity">