1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | /* * Created by SharpDevelop. * User: wai * Date: 2/9/2012 * Time: 15:34 * * To change this template use Tools | Options | Coding | Edit Standard Headers. */ using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; namespace HelloWorld { public partial class MainForm : Form { public MainForm() { InitializeComponent(); this.Size = new Size(220, 150); Button button = new Button(); button.Name = "Button01"; button.Text = "Hi"; button.Location = new Point(0,0); button.Size = new Size(100, 40); button.Click += new EventHandler(Click); this.Controls.Add(button); } private void Click(object sender, EventArgs e) { MessageBox.Show("Wow", "Message"); } } } |
Sunday, September 2, 2012
Hello World 2 (C#)
Hello World (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 | using System; namespace HelloWorld { class Program { public static void Main(string[] args) { Console.Write("Hello World !"); Console.ReadKey(true); } } } |
Simple Vertical ScrollView (android)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | package com.test; import android.app.Activity; import android.os.Bundle; import android.view.ViewGroup.LayoutParams; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ScrollView; public class VerticalScrollViewActivity extends Activity { ImageView i; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout l = new LinearLayout(this); l.setOrientation(LinearLayout.VERTICAL); i = new ImageView(this); i.setImageResource(R.drawable.android); i.setPadding(5, 5, 0, 0); l.addView(i,new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT)); i = new ImageView(this); i.setImageResource(R.drawable.android); i.setPadding(5, 5, 0, 0); l.addView(i,new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT)); i = new ImageView(this); i.setImageResource(R.drawable.android); i.setPadding(5, 5, 0, 0); l.addView(i,new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT)); i = new ImageView(this); i.setImageResource(R.drawable.android); i.setPadding(5, 5, 0, 0); l.addView(i,new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT)); i = new ImageView(this); i.setImageResource(R.drawable.android); i.setPadding(5, 5, 0, 0); l.addView(i,new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT)); i = new ImageView(this); i.setImageResource(R.drawable.android); i.setPadding(5, 5, 0, 0); l.addView(i,new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT)); ScrollView m_Scroll = new ScrollView(this); m_Scroll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); m_Scroll.addView(l, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT) ); m_Scroll.setOverScrollMode(1); m_Scroll.setSmoothScrollingEnabled(true); //addContentView(m_Scroll, new LayoutParams(LayoutParams.FILL_PARENT, //LayoutParams.WRAP_CONTENT)); setContentView(m_Scroll); } } |
Friday, August 31, 2012
Location service (android)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | public class LocationTestActivity extends Activity implements LocationListener { private LocationManager service; private TextView tv; private String provider; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); tv = (TextView) findViewById(R.id.display); // Get the location manager service = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); provider = service.getBestProvider(criteria, false); Location location = service.getLastKnownLocation(provider); // Initialize the location fields if (location != null) { onLocationChanged(location); } else { tv.setText("Location not available"); } boolean enabled = service.isProviderEnabled(LocationManager.GPS_PROVIDER); if (!enabled) { Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(intent); } } public void onLocationChanged(Location arg0) { //int lat = (int) (location.getLatitude()); //int lng = (int) (location.getLongitude()); //latituteField.setText(String.valueOf(lat)); //longitudeField.setText(String.valueOf(lng)); String lat = String.valueOf(arg0.getLatitude()); String lon = String.valueOf(arg0.getLongitude()); Log.e("GPS", "location changed: lat="+lat+", lon="+lon); tv.setText("lat="+lat+", lon="+lon); } public void onProviderDisabled(String arg0) { Toast.makeText(this, "Disabled provider " + provider,Toast.LENGTH_SHORT).show(); Log.e("GPS", "provider disabled " + arg0); } public void onProviderEnabled(String arg0) { Toast.makeText(this, "Enabled new provider " + provider, Toast.LENGTH_SHORT).show(); Log.e("GPS", "provider enabled " + arg0); } public void onStatusChanged(String arg0, int arg1, Bundle arg2) { Log.e("GPS", "status changed to " + arg0 + " [" + arg1 + "]"); } /* Request updates at startup */ @Override protected void onResume() { super.onResume(); service.requestLocationUpdates(provider, 400, 1, this); } /* Remove the locationlistener updates when Activity is paused */ @Override protected void onPause() { super.onPause(); service.removeUpdates(this); } } |
Simple ListView 2 - with Dialog (android)
public class HelloListViewActivity extends ListActivity {
String[] data;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// storing string resources into Array
data = getResources().getStringArray(R.array.data);
// Binding resources Array to ListAdapter
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_cell, R.id.label, data));
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
createDialog(data[position]);
}
});
}
private void createDialog(String s)
{
new AlertDialog.Builder(this)
.setTitle("Message")
.setMessage("Go to " + s + " page ?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
})
.show();
}
}
Thursday, August 30, 2012
Simple ListView (android)
res/layout/list_cell.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Single List Item Design -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:textSize="16dip"
android:textStyle="bold" >
</TextView>
res/values/list.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="data">
<item>Apple</item>
<item>Orange</item>
<item>Banana</item>
<item>Milk</item>
</string-array>
</resources>
import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class HelloListViewActivity extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// storing string resources into Array
String[] data = getResources().getStringArray(R.array.data);
// Binding resources Array to ListAdapter
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_cell, R.id.label, data));
}
Subscribe to:
Posts (Atom)





