Tag Archives: android

Android Spinner and Dialog

1-custom-dialog-show
2-spinner-listner
3-spinner-access
4-spinner-id


how-display-custom-dialog-your-android-application
dialogs

package com.pmkap.SpinnerAndDialog;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

public class SpinnerAndDialogActivity extends Activity {
	private Button btnSave; 
	private EditText etWorkout;
	private TextView tvHome;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        tvHome = (TextView) findViewById(R.id.tvHome);
        
        Dialog dialog = new Dialog(SpinnerAndDialogActivity.this);

        dialog.setContentView(R.layout.custom_dialog);
        dialog.setTitle("Custom Dialog");
        dialog.setCancelable(true);

        TextView text = (TextView) dialog.findViewById(R.id.text);
        text.setText("Hello, this is a custom dialog!");
        ImageView image = (ImageView) dialog.findViewById(R.id.image);
        image.setImageResource(R.drawable.ic_launcher);
        btnSave = (Button)dialog.findViewById(R.id.btnSave);
        etWorkout = (EditText)dialog.findViewById(R.id.etWorkout);
        btnSave.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				tvHome.setText(etWorkout.getText().toString() + " - ");
			}
		});
        dialog.show();
    }
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:padding="10dp" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_marginRight="10dp"
        android:src="@drawable/ic_launcher" />


    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="Hello, this is a custom dialog!"
        android:textColor="#FFF" />

    </LinearLayout>
    


    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >


        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Workout"
            android:padding="10dp"
            android:textAppearance="?android:attr/textAppearanceMedium" />


        <EditText
            android:id="@+id/etWorkout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:padding="10dp" >

            <requestFocus />
        </EditText>
    
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >


        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:text="Muscle Group"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <Spinner
            android:id="@+id/spinner1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
    		android:padding="10dp"
            android:layout_weight="1" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
            android:padding="10dp" >




        <Button
            android:id="@+id/btnSave"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Save" />

    </LinearLayout>


</LinearLayout>
<?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/tvHome"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

</LinearLayout>

android-spinner-drop-down-list-example
hello-spinner

package com.pmkap.spinner;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class SpinnerActivity extends Activity {
	private TextView tvValue;
	private Spinner spMuscleGroup;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        tvValue = (TextView)findViewById(R.id.tvValue);
        spMuscleGroup = (Spinner)findViewById(R.id.spMuscleGroup);
        
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
                this, R.array.MuscleGroup, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spMuscleGroup.setAdapter(adapter);
        
        spMuscleGroup.setOnItemSelectedListener(new MyOnItemSelectedListener());
        
    }
    public class MyOnItemSelectedListener implements OnItemSelectedListener {

        public void onItemSelected(AdapterView<?> parent,
            View view, int pos, long id) {
          Toast.makeText(parent.getContext(), "The planet is " +
              parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();
          tvValue.setText(parent.getItemAtPosition(pos).toString());
        }

        public void onNothingSelected(AdapterView parent) {
          // Do nothing.
        }
    }
}
<?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/tvValue"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="Change the SpinnerView" />




    <Spinner
        android:id="@+id/spMuscleGroup"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp" />

</LinearLayout>
    <string-array name="MuscleGroup">
        <item >Chest</item>
        <item >Shoulder</item>
        <item >Biceps</item>
        <item >Triceps</item>
        <item >Lat</item>
        <item >Back</item>
        <item >Legs</item>
        <item >Abbs</item>
    </string-array>

android-spinner-drop-down-list-example

package com.pmkap.spinner;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;

public class SpinnerActivity extends Activity {
	private TextView tvValue;
	private Spinner spMuscleGroup;
	private Button btnRefresh;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        tvValue = (TextView)findViewById(R.id.tvValue);
        spMuscleGroup = (Spinner)findViewById(R.id.spMuscleGroup);
        btnRefresh = (Button)findViewById(R.id.btnRefresh);
        
        btnRefresh.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				tvValue.setText(String.valueOf(spMuscleGroup.getSelectedItem()));
			}
		});
    }
}
<?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/tvValue"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="Change the SpinnerView" />
    <Spinner
        android:id="@+id/spMuscleGroup"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:entries="@array/MuscleGroup" />
    <Button
        android:id="@+id/btnRefresh"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:text="Refresh" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">Spinner</string>
    <string-array name="MuscleGroup">
        <item >Chest</item>
        <item >Shoulder</item>
        <item >Biceps</item>
        <item >Triceps</item>
        <item >Lat</item>
        <item >Back</item>
        <item >Legs</item>
        <item >Abbs</item>
    </string-array>

</resources>

spinner-adding-string-array-on-item-selection-how-can-get-item-related-value-in

package com.pmkap.spinner;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;

public class SpinnerActivity extends Activity {
	private TextView tvValue;
	private Spinner spMuscleGroup;
	private Button btnRefresh;
	private String values [];
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        tvValue = (TextView)findViewById(R.id.tvValue);
        spMuscleGroup = (Spinner)findViewById(R.id.spMuscleGroup);
        btnRefresh = (Button)findViewById(R.id.btnRefresh);
        values =  getResources().getStringArray(R.array.MuscleGroupValues);
        
        btnRefresh.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				tvValue.setText(String.valueOf(spMuscleGroup.getSelectedItem()) 
						+ " - " + values[spMuscleGroup.getSelectedItemPosition()]);
			}
		});
    }
}
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">Spinner</string>
    <string-array name="MuscleGroup">
        <item >Chest</item>
        <item >Shoulder</item>
        <item >Biceps</item>
        <item >Triceps</item>
        <item >Lat</item>
        <item >Back</item>
        <item >Legs</item>
        <item >Abbs</item>
    </string-array>
    <string-array name="MuscleGroupValues">
        <item >C</item>
        <item >S</item>
        <item >B</item>
        <item >T</item>
        <item >L</item>
        <item >K</item>
        <item >G</item>
        <item >A</item>
    </string-array>

</resources>
<?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/tvValue"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="Change the SpinnerView" />
    <Spinner
        android:id="@+id/spMuscleGroup"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:entries="@array/MuscleGroup" />
    <Button
        android:id="@+id/btnRefresh"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:text="Refresh" />
</LinearLayout>

Android Context Menu

context menu
android-long-click-context-menu/
show-a-context-menu-for-long-clicks-in-an-android-listview/
android-access-child-views-from-a-listview

registerForContextMenu(lvWeightReps);
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;menu xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot; &gt;
	&lt;item android:id=&quot;@+id/context_workout_delete&quot;
		  android:title=&quot;delete&quot; /&gt;
&lt;/menu&gt;
	@Override
	public void onCreateContextMenu(ContextMenu menu, View v,
	    ContextMenuInfo menuInfo) {
		super.onCreateContextMenu(menu, v, menuInfo);
		if (v.getId()==R.id.lvWeightReps) {
		    MenuInflater inflater = getMenuInflater();
		    inflater.inflate(R.menu.context_workout, menu);
			/*menu.setHeaderTitle(&quot;Title&quot;);
			for (int i = 0; i&lt;2; i++) {
				menu.add(Menu.NONE, i, i, &quot;hmm&quot;);
			}*/
		}
	}
	@Override
	public boolean onContextItemSelected(MenuItem item) {
	    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
	            .getMenuInfo();
	 
	    switch (item.getItemId()) {
	    case R.id.context_workout_delete:
	        remove(info.position);
	        return true;
	    }
	    return false;
	}
	private void remove(int pos){
		View v = lvWeightReps.getChildAt(pos);
		TextView txtId = (TextView)v.findViewById(R.id.weightrep_id);
		String id = txtId.getText().toString();
		DB.execSQL(&quot;DELETE FROM &quot; +
        		WEIGHTREP_TABLE_NAME +
    			&quot; where rowid = &quot;+id+&quot;;&quot;);
		displayList();
	}

cascading delete

delete from weightreps where dayid in (select rowid from sets where workoutid = 1)
delete from sets where workoutid = 1
delete from workouts where rowid = 1

more android – layout weights

#designed homeactivity and registeractivity
#homeactivity is white
#homeactivity is vertically divided to two – new layout – table – 2 rows – distribute weights evenly
#homeactivity has two big image with text on top buttons in the divisions

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    
    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >
    </TableRow>
    
    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >

    </TableRow>

</TableLayout>
   android:gravity="center_vertical|center_horizontal"
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    
    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" 
    	android:gravity="center_vertical|center_horizontal" >

        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical" >

                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_vertical|center_horizontal"
                    android:text="Register"
                    android:textAppearance="?android:attr/textAppearanceLarge" />

                <ImageButton
                    android:id="@+id/imageButton1"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:src="@drawable/register" />

            </LinearLayout>

        </FrameLayout>

    </TableRow>
    
    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="center_vertical|center_horizontal" >

        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical" >


                <TextView
                    android:id="@+id/textView2"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_vertical|center_horizontal"
                    android:text="Search"
                    android:textAppearance="?android:attr/textAppearanceLarge" />

                <ImageButton
                    android:id="@+id/imageButton2"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:src="@drawable/search" />

            </LinearLayout>

        </FrameLayout>

    </TableRow>

</TableLayout>

todo: dynamic layouts

http://twigstechtips.blogspot.in/2011/01/android-how-to-hide-view-and-collapse.html
http://www.dreamincode.net/forums/topic/130521-android-part-iii-dynamic-layouts/

before that workout log

screen 1

lblNoRecords.setVisibility(View.GONE);
lblNoRecords.setVisibility(View.VISIBLE);

workout = DatabaseUtils.sqlEscapeString(workout);
it comes with added single quotes at the end
http://developer.android.com/reference/android/database/DatabaseUtils.html

Cursor c = DB.rawQuery("SELECT rowid,WorkoutName FROM " +
        		WORKOUTS_TABLE_NAME +
    			" where MuscleGroupCode = '"+cSwitchGroup+"' "+
        		"order by rowid", null);
String rowid = c.getString(c.getColumnIndex("rowid"));
item.put("workout_rowid", rowid);

round about way, but im still doing it
http://sqlite.org/autoinc.html

this error means – wrong column name (row 0 col -1)
http://stackoverflow.com/questions/4810048/illegalstateexception-get-field-slot-from-row-0-col-1-failed

strftime(‘%s’,'now’) – makes an integer time stamp
date(strftime(‘%s’,'now’),’unixepoch’) – retreives from timestamp to string date format
http://www.sqlite.org/lang_datefunc.html
http://sqliteadmin.orbmu2k.de/

public void onResume() {
		super.onResume();
		displayList();
	}

back button previous activity
http://stackoverflow.com/questions/5019686/what-methods-are-invoked-in-the-activity-lifecycle-in-the-following-cases

Basic Android Lists

  1. Single item - ArrayAdapter

    txtNote = (EditText)findViewById(R.id.txtNote);
    btnAdd = (ImageButton)findViewById(R.id.btnAdd);
    lstNotes = (ListView)findViewById(R.id.lstNotes);
    adapter = new ArrayAdapter(AddNewListOfNotes.this,R.layout.listnotes);
    lstNotes.setAdapter(adapter);
    btnAdd.setOnClickListener(new View.OnClickListener() {
    	public void onClick(View v) {
    		adapter.add(txtNote.getText().toString());
    	}
    });

    http://stackoverflow.com/questions/4645854/add-data-from-edittext-to-listview-in-android

  2. on click listeners
    lstNotes.setOnItemClickListener(new OnItemClickListener(){
    	public void onItemClick(AdapterView parent, View view, int position, long id) {
    		Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_SHORT).show();
    	}
    });

    http://www.mkyong.com/android/android-listview-example/

  3. single item – array adapter with complex layout – reference id of textview
    <?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:background="#FFFFFF"  >
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >
            <EditText
                android:id="@+id/txtNote"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1.06"
                android:ems="10" >
                <requestFocus />
            </EditText>
            <ImageButton
                android:id="@+id/btnAdd"
                android:layout_width="47dp"
                android:layout_height="fill_parent"
                android:src="@drawable/ic_menu_add" />
        </LinearLayout>
        <ListView
            android:id="@+id/lstNotes"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >
        </ListView>
    </LinearLayout>
    <?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="horizontal" >
        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ok" />
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >
            <TextView
                android:id="@+id/txtHeading"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:textColor="#090909" />
            <TextView
                android:id="@+id/txtSubHeading"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Small Text"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textColor="#090909" />
        </LinearLayout>
    </LinearLayout>
    package com.example.helloandroid;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.ArrayAdapter;
    import android.widget.EditText;
    import android.widget.ImageButton;
    import android.widget.TextView;
    import android.widget.Toast;
    import android.widget.ListView;
    import android.widget.AdapterView.OnItemClickListener;
    
    public class AddNewListOfNotes extends Activity {
    	private EditText txtNote;
    	private ImageButton btnAdd;
    	private ListView lstNotes;
    	private ArrayAdapter adapter;
    	@Override
    	public void onCreate(Bundle savedInstanceState) {
    	    super.onCreate(savedInstanceState);
    
            setContentView(R.layout.addnewlistofnotes);
    		txtNote = (EditText)findViewById(R.id.txtNote);
    		btnAdd = (ImageButton)findViewById(R.id.btnAdd);
    		lstNotes = (ListView)findViewById(R.id.lstNotes);
    		adapter = new ArrayAdapter(AddNewListOfNotes.this,R.layout.listnotes,R.id.txtHeading);
    		lstNotes.setAdapter(adapter);
    
    		btnAdd.setOnClickListener(new View.OnClickListener() {
    
    			public void onClick(View v) {
    				adapter.add(txtNote.getText().toString());
    				txtNote.setText("");
    			}
    		});
    		lstNotes.setOnItemClickListener(new OnItemClickListener(){
    
    			public void onItemClick(AdapterView parent, View view, int position,
    					long id) {
    				Toast.makeText(getApplicationContext(),
    						((TextView)view.findViewById(R.id.txtHeading)).getText(), Toast.LENGTH_SHORT).show();
    
    			}
    		});
    	}
    }


    android-listview-example

  4. binding more items

    - thanks to vogella.com_tutorial_twolistitems and adapter.notifyDataSetChanged(); from many crazy links which made me pretty scared if I had to code that much!!! but thank god custom adapter was not needed, a simple adapter was enough!

    public class AddNewListOfNotes extends Activity {
    	private EditText txtNote;
    	private ImageButton btnAdd;
    	private ListView lstNotes;
    	private SimpleAdapter adapter;
    	private int count = 1;
    	private ArrayList<Map<String, String>> list = new ArrayList<Map<String, String>>();;
    	@Override
    	public void onCreate(Bundle savedInstanceState) {
    	    super.onCreate(savedInstanceState);
    
            setContentView(R.layout.addnewlistofnotes);
    		txtNote = (EditText)findViewById(R.id.txtNote);
    		btnAdd = (ImageButton)findViewById(R.id.btnAdd);
    		lstNotes = (ListView)findViewById(R.id.lstNotes);
    		String[] from = { "heading", "subheading" };
    		int[] to = { R.id.txtHeading, R.id.txtSubHeading };
    		adapter = new SimpleAdapter (this, list, R.layout.listnotes, from, to);
    		lstNotes.setAdapter(adapter);
    		
    		btnAdd.setOnClickListener(new View.OnClickListener() {			
    			public void onClick(View v) {
    				HashMap<String, String> item = new HashMap<String, String>();
    				item.put("heading", txtNote.getText().toString());
    				item.put("subheading", Integer.toString(count));
    				list.add(item);
    				adapter.notifyDataSetChanged();
    				count++;
    				txtNote.setText("");
    			}
    		});
    		lstNotes.setOnItemClickListener(new OnItemClickListener(){		
    			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    				Toast.makeText(getApplicationContext(),
    						((TextView)view.findViewById(R.id.txtHeading)).getText(), Toast.LENGTH_SHORT).show();
    				
    			}			
    		});        
    	}
    }


    another

  5. other

    ImageView imageView=(ImageView) view.findViewById(R.id.imageView1);
    if((String) imageView.getTag() != "x"){
        imageView.setImageResource(R.drawable.x);
    	imageView.setTag("x");
    }
    else{
        imageView.setImageResource(R.drawable.ok);
    	imageView.setTag("");
    }

Basics Android Activities

  1. just created my first activity, reminds me of a mvc plugin to visual studio
    simply wonderfull
    http://stackoverflow.com/questions/2337874/best-way-to-add-activity-to-an-android-project-in-eclipse
  2. hmm, i missed that one.. new android layout
    http://stackoverflow.com/questions/9194366/how-to-create-a-new-layout-for-an-android-project-using-eclipse
  3. opening/showing new activity
    Intent myIntent = new Intent(HelloAndroidActivity.this,AddNewListOfNotes.class);
    HelloAndroidActivity.this.startActivity(myIntent);

    http://www.dotnetexpertsforum.com/how-to-open-a-new-activity-from-button-click-in-android-t1322.html

  4. communication activity to activity
    myIntent.putExtra("Name","Manoj");

    and

    getIntent().getStringExtra("Name")

    http://stackoverflow.com/questions/4046612/activity-to-activity-communication

  5. first/home activity among many
    http://stackoverflow.com/questions/4642993/help-with-first-android-activity

Basic GUI programming in android

how to -

  1. layout?
  2. textbox?
  3. button?
  4. new activity?
  5. strings?
  6. communication between activities?

Best features in eclipse adt/android

  1. res/layout/main.xml Graphic layout
  2. res/values/strings.xml Resources
  3. Amazing debugger and intellisense
  4. Packages: http://developer.android.com/reference/packages.html i would like to quote starting android.widget.TextView and android.widget.EditText
  5. My first edittext widget(textbox control) set/get
    EditText txtName;
    txtName = (EditText)findViewById(R.id.txtName);
    txtName.setText('0');
    txtName.getText();

    http://www3.ntu.edu.sg/home/ehchua/programming/android/Android_BasicsUI.html

  6. My first button click
    Button button = ((Button)findViewById(R.id.btnSave));
    button.setOnClickListener(new View.OnClickListener(){
    	public void onClick(View v){
    	// Perform action on clicks
    	}
    });
  7. anonymous object of an interface with a method!
    the beauty of this piece of code is, OnClickListener is an interface
    http://www.jameselsey.co.uk/blogs/techblog/binding-your-buttons-to-your-activity-the-easy-way/
  8. My first toast(message box)
    Toast.makeText(HelloAndroidActivity.this, '...', Toast.LENGTH_SHORT).show();
  9. A new activity class for every window, appending the res/AndroidManifest.xml
  10. Layouts prety confusing, i went with just the knowledge of the default Vertical linear layout adding widgets one below the other

The GUI programing in android

  1. layers – presentation layer has a GUI editor where u can add presentation controls and edit their id’s which get stored on an xml version. awesome is this xml gets converted to a java class automatically. in the programing layer, the fascinating cross layer function findobjectbyid is used – the object equvalent is derived here
  2. manipulations and access – using the object get and set methods can be used
  3. abstraction – what cant be seen here is the moment the activity class was extended with it must come events which paint the screen after events and such thus bringing to light our changes made in step 2! – totally essential to understand the flow of architecture
  4. wow – on the create event we bind a function to on-click of a button such that it does not execute then at that point but executes when the button is clicked, awesome.

The layout.xml is not scary anymore, to an extent I have started to read it successfully.

next up – database, lists/buttons/dynamic programming and communicating between activities

how to make an anroid application

a sudden dream
instead of showing my client a web application on a laptop, i dream of the laptop/mobile/tablet outputs, for which I would need new designs for mobile interface as well as knowledge on android programming, sounds like the future, all of these things together so why not today…

googled how to make an anroid application
http://developer.android.com/resources/tutorials/hello-world.html

eclipse not classic but jee version, adt plugin instlation was problematic

finally, my first android activity…