Hi,
Thanks for the reply. I have already added the new activity or secocnd
activity in the AndroidManifest.xml file. I tried adding
getApplicationContext() in the intent. But still its not working. I am
herewith adding my code and also the AndroidManifest.xml file for
currency convertor. Could you please look in to the same and let me
know where am going wrong.
Thanks in advance,
Naina
1st activity:
package com.example.android.Convertor;
import android.view.View;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AdapterView.OnItemClickListener;
import android.content.Intent;
public class Convertor extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String[] convertors =
getResources().getStringArray(R.array.converters_array);
setListAdapter(new
ArrayAdapter<String>(this,R.layout.list,convertors));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent intent = new
Intent( getApplicationContext(),currency.class);
startActivity(intent);
}
});
}
}
2nd activity:
package com.example.android.Convertor;
import android.view.View;
import android.widget.TextView;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.content.Intent;
public class currency extends Activity {
private EditText rate;
private EditText curr;
private TextView Exchngtext;
private TextView localcurtext;
private TextView Foreincurtext;
private TextView Foreincurval;
private Button btncalculate;
private Button btnclear;
private double exchngrt = 0;
private double loclcurr = 0;
private double forgncurr = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.main);
initControls();
setResult(RESULT_OK);
finish();
}
private void initControls()
{
Exchngtext = (TextView)findViewById(R.id.Exchngtext);
rate = (EditText)findViewById(R.id.rate);
localcurtext =(TextView)findViewById(R.id.localcurtext);
curr = (EditText)findViewById(R.id.curr);
Foreincurtext =(TextView)findViewById(R.id.Foreincurtext);
Foreincurval = (TextView)findViewById(R.id.foreign);
btncalculate = (Button)findViewById(R.id.btncalculate);
btnclear = (Button)findViewById(R.id.btnclear);
btncalculate.setOnClickListener(new Button.OnClickListener() { public
void onClick (View v){ calculate(); }});
btnclear.setOnClickListener(new Button.OnClickListener() { public
void onClick (View v){ clear(); }});
}
private void calculate()
{
exchngrt=Double.parseDouble(rate.getText().toString());
loclcurr=Double.parseDouble(curr.getText().toString());
forgncurr=(exchngrt*loclcurr);
Foreincurval.setText(Double.toString(forgncurr));
Foreincurval.setEnabled(false);
}
private void clear()
{
rate.setText("");
curr.setText("");
Foreincurval.setText("");
}
}
AndroidManifest.xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.Convertor"
android:versionCode="1"
android:versionName="1.0.0">
<application android:icon="@drawable/icon" android:label="@string/
app_name">
<activity android:name=".Convertor"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.settings.LOCALE_SETTINGS"></
action>
</intent-filter>
</activity>
<activity android:name=".currency">
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category
android:name="android.intent.category.DEFAULT" />
</intent-filter> </activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission
android:name="android.permission.CHANGE_CONFIGURATION"/>
<uses-permission android:name="android.permission.SEND_SMS"/>
</manifest>
On Feb 27, 2:49 am, Gaunt Face <[email protected]> wrote:
> To launch a new activity you should be using code something like this:
>
> Intent intent = new Intent(getApplicationContext(),
> ClassNameHere.class);
> startActivity(intent);
>
> Then you also need to add your Activity to the AndroidManifest.xml
> file, if your using eclipse you can open the AndroidManifest file and
> go to:
>
> Application (Tab) > *scroll to bottom* > Add > Select Activity > Then
> copy the fields from the existing Activity
>
> This will create the xml for you, which will look a little something
> like:
>
> <activity android:name=".ClassName" android:label="@string/app_name"></
> activity>
>
> Hope that helps,
> Matt
>
> On Feb 25, 11:02 am, NewDev <[email protected]> wrote:
>
> > Hi,
>
> > I am new to android. I am trying to write a small application.
> > I have one screen(activity), on clicking it should open another screen
> > (activity). I am trying to use intents. But somehow my application is
> > not working.
> > I have a list of items for Tip calculator and Currency calculator
> > (using listView), on clicking on one item for Tip calculator, another
> > screen should open that has tip calculator screen. Where there are
> > buttons for entering the amount and percentage amount for tip.
>
> > I am writing the intent as the following in the Convertor
> > screen(activity):
> > Intent intent = new Intent( Convertor.this,tip.class);
> > startActivity(intent);
>
> > Now I am not able to get what to be written for intent in the tip.
> > class,i.e., in another activity where the implementation for tip is
> > present.
>
> > Could anybody can help me?
>
> > Thanks in advance,
>
> > naina
>
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en