Posts Tagged tutorial

C++ Eclipse Install CDT and MinGW GCC Plugin

I just succesfully installed c++ on eclipse using the CDT C++ plugin and MinGW compiler for windows Vista. There are a lot of plugins to get working. There were a few things that I had to set up, no doubt, so here are some notes for those of you trying to do the same thing:

0. Obviously you need to have downloaded eclipse first http://www.eclipse.org

1. Download the  Eclipse CDT Plugin http://www.eclipse.org/cdt/

2.  Now because I am on windows I need to install a c++ compiler (the CDT plugin doesn’t come with one!), so the recommended one is MinGW. Here is a link that says exactly how to install it, and exactly what you will need to install. http://www.mingw.org/wiki/Getting_Started. Note that there is an automatic installer.

At this point, DO NOT FORGET TO SET YOUR PATH VARIABLE! This is very easy on windows; http://www.java.com/en/download/help/path.xml this says how to do it.

If you happen to get the error:”Your connection appears to have dropped out. Reconnect your dial up or check your IE proxy settings.” then this means that sourceforge is having trouble downloading the file. What you should do is first make sure the installer is not on your desktop, retry it a few times, and then set your source forge default mirror settings - this can be done by signing up for a sourceforge account and then going to your account  https://sourceforge.net/account/ and clicking the Default Download Mirror under the main preferences page.

3. Now follow this guide to setting up the code environment - it is a little outdated but you should be able to follow it pretty easily:

http://www.codeproject.com/KB/tips/CPP_Dev_eclipse_CDT.aspx

4. Finally, you will need to set the path of the ‘includes’ library, so to do this, go to Project -> properties -> C/C++ general -> Paths and Symbols, then click on the ‘Includes Tab (first one), and under languages go to GNU C++, then click on the ‘Add…’ button the right, and then select the folder C:\MinGW\include, and press enter.

Done!

Tags: , , , , , , , , ,

Android TabHost Basic Code Example

Here is a basic example of a TabHost, which allows a user to create a tabs view (the default android ‘contacts/dialer’ menu uses tabhost).

First, the code:

package com.android.mytabviewtest;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class tabViewTest2 extends Activity {

private int ADD_NEW_TAB = Menu.FIRST;

@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
TabHost tabs = (TabHost) this.findViewById(R.id.my_tabhost);
tabs.setup();
TabSpec tspec1 = tabs.newTabSpec(”First Tab”);
tspec1.setIndicator(”One”);
tspec1.setContent(R.id.content);
tabs.addTab(tspec1);
TabSpec tspec2 = tabs.newTabSpec(”Second Tab”);
tspec2.setIndicator(”Two”);
tspec2.setContent(R.id.content);
tabs.addTab(tspec2);
TabSpec tspec3 = tabs.newTabSpec(”Third Tab”);
tspec3.setIndicator(”Three”);
tspec3.setContent(R.id.content);
tabs.addTab(tspec3);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);

menu.add(0, ADD_NEW_TAB, 0, “New Tabs”);
return true;
}

//Dynamically delete tabs, then add one again
//Problem with SDK 1.1 returns null pointer exception
@Override
public boolean onOptionsItemSelected(MenuItem item) {

TabHost tabs = (TabHost) this.findViewById(R.id.my_tabhost);
tabs.clearAllTabs();
tabs.setup();
TabSpec tspec1 = tabs.newTabSpec(”New Tab”);
tspec1.setIndicator(”NEWTAB”, this.getResources().getDrawable(R.drawable.icon));
tspec1.setContent(R.id.content);
tabs.addTab(tspec1);

return super.onOptionsItemSelected(item);
}
}

Now, the XML (i.e. main.xml):

<?xml version=”1.0″ encoding=”utf-8″?>
<TabHost xmlns:android=”http://schemas.android.com/apk/res/android”
android:id=”@+id/my_tabhost”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”>
<TabWidget
android:id=”@android:id/tabs”
android:layout_width=”fill_parent”
android:layout_height=”65px”/>

<FrameLayout
android:id=”@android:id/tabcontent”
android:layout_width=”fill_parent”
android:layout_height=”200px”
android:paddingTop=”65px”>
<LinearLayout
android:id=”@+id/content”
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”>
</LinearLayout>
</FrameLayout>
</TabHost>

For more information, follow this link to the documentation for a TabHost.

http://developer.android.com/reference/android/widget/TabHost.html

Tags: , , , , , , , ,

Basic Android Tutorial: Countdown Timer Code

Here is some basic code to make a timer that counts down.

You can specify the start value you want and the amount you want it to count down by.

package com.android.countdown;
import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.widget.TextView;

public class CountDownTest extends Activity {

TextView tv; //textview to display the countdown

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

tv = new TextView(this);
this.setContentView(tv);

//5000 is the starting number (in milliseconds)
//1000 is the number to count down each time (in milliseconds)
MyCount counter = new MyCount(5000,1000);

counter.start();

}

//countdowntimer is an abstract class, so extend it and fill in methods
public class MyCount extends CountDownTimer{

public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}

@Override
public void onFinish() {
tv.setText(”done!”);
}

@Override
public void onTick(long millisUntilFinished) {
tv.setText(”Left: ” + millisUntilFinished/1000);

}

}
}

Tags: , , , , , , , ,