Well i made this and it works for me
*This is the manifest file*
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pas.Hari.com"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon"
android:label="@string/app_name">
<activity android:name=".TestHari"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DetList"/>
</application>
<uses-sdk android:minSdkVersion="4" />
</manifest>
*THis is the DetList class*
package pas.Hari.com;
import android.app.Activity;
import android.os.Bundle;
public class DetList extends Activity{
String i1;
String i2;
String i3;
String i4;
String i5;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.details);
}
}
*And this is the TestHari class*
package pas.Hari.com;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class TestHari extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button yes=(Button)findViewById(R.id.yes);
yes.setOnClickListener(onYes);
}
private View.OnClickListener onYes=new View.OnClickListener()
{
public void onClick(View v)
{
Intent i=new Intent(TestHari.this, DetList.class);
startActivity(i);
}
};
}
the *DetList *shows Ok on the emulator. the xml files are the same as you
provided
////////////////////////////////////////////////////////////////
2010/11/23 hari <[email protected]>
> i am still facing a minor problem with this...
>
> I created the view... But i donno where i should enter the xml layout
> for it... Let me paste the code here... pls have a look n tell me what
> to do ...
>
> This is the initial code that will load a simple form
>
> --------------------------------------------------------------------------------------
> package hari.rts;
>
> import android.app.Activity;
> import android.content.Intent;
> import android.os.Bundle;
> import android.view.View;
> import android.widget.Button;
>
> public class supermarket extends Activity {
> /** Called when the activity is first created. */
> @Override
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> setContentView(R.layout.main);
> Button yes=(Button)findViewById(R.id.yes);
> yes.setOnClickListener(onYes);
> }
> private View.OnClickListener onYes=new View.OnClickListener()
> {
> public void onClick(View v)
> {
> Intent i=new Intent(supermarket.this, List.class);
> startActivity(i);
> }
> };
> }
>
> This is the layout for the above code (main.xml):
>
> -------------------------------------------------------------------------------------
> <?xml version="1.0" encoding="utf-8"?>
> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
> android"
> android:orientation="vertical"
> android:layout_width="fill_parent"
> android:layout_height="fill_parent"
> >
> <TextView
> android:layout_width="fill_parent"
> android:layout_height="wrap_content"
> android:text="Welcome to the market"
> />
> <TextView
> android:layout_width="fill_parent"
> android:layout_height="wrap_content"
> android:text="Do you want to use the easy-shopping service?"
> />
> <Button android:id="@+id/yes"
> android:layout_width="fill_parent"
> android:layout_height="wrap_content"
> android:text="Yes"
> />
> <Button android:id="@+id/no"
> android:layout_width="fill_parent"
> android:layout_height="wrap_content"
> android:text="No"
> />
> </LinearLayout>
>
> This is the 2nd form that gives a list of items with checkboxes:
>
> --------------------------------------------------------------------------------------------------------------
> package hari.rts;
>
>
>
> import android.app.Activity;
> import android.content.Intent;
> import android.os.Bundle;
> import android.view.View;
> import android.view.View.OnClickListener;
> import android.widget.Button;
> import android.widget.CheckBox;
> public class List extends Activity
> {
> String i1;
> String i2;
> String i3;
> String i4;
> String i5;
> @Override
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> setContentView(R.layout.details);
> final CheckBox checkbox1 = (CheckBox) findViewById(R.id.check1);
> final CheckBox checkbox2 = (CheckBox) findViewById(R.id.check2);
> final CheckBox checkbox3 = (CheckBox) findViewById(R.id.check3);
> final CheckBox checkbox4 = (CheckBox) findViewById(R.id.check4);
> final CheckBox checkbox5 = (CheckBox) findViewById(R.id.check5);
> checkbox1.setOnClickListener(new OnClickListener() {
> public void onClick(View v) {
> // Perform action on clicks, depending on whether it's now
> checked
> if (((CheckBox) v).isChecked()) {
> i1="item1";
> }
> else
> {
> i1="";
> }
> }
> });
> checkbox2.setOnClickListener(new OnClickListener() {
> public void onClick(View v) {
> // Perform action on clicks, depending on whether it's now
> checked
> if (((CheckBox) v).isChecked()) {
> i2="item2";
> }
> else
> {
> i2="";
> }
> }
> });
> checkbox3.setOnClickListener(new OnClickListener() {
> public void onClick(View v) {
> // Perform action on clicks, depending on whether it's now
> checked
> if (((CheckBox) v).isChecked()) {
> i3="item3";
>
> }
> else
> {
> i3="";
> }
> }
> });
> checkbox4.setOnClickListener(new OnClickListener() {
> public void onClick(View v) {
> // Perform action on clicks, depending on whether it's now
> checked
> if (((CheckBox) v).isChecked()) {
> i4="item4";
>
> }
> else
> {
> i4="";
> }
> }
> });
> checkbox5.setOnClickListener(new OnClickListener() {
> public void onClick(View v) {
> // Perform action on clicks, depending on whether it's now
> checked
> if (((CheckBox) v).isChecked()) {
> i5="item5";
>
> }
> else
> {
> i5="";
> }
> }
> });
> Button submit=(Button)findViewById(R.id.submit);
> submit.setOnClickListener(onSubmit);
> }
> private View.OnClickListener onSubmit=new View.OnClickListener()
> {
> public void onClick(View v)
> {
> Intent j=new Intent(List.this, confirm.class);
> j.putExtra("key1",i1);
> j.putExtra("key2",i2);
> j.putExtra("key3",i3);
> j.putExtra("key4",i4);
> j.putExtra("key5",i5);
> startActivity(j);
> }
> };
> }
>
> This is the layout for the above file (details.xml):
>
> -------------------------------------------------------------------------------------
> <?xml version="1.0" encoding="utf-8"?>
> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
> android"
> android:orientation="vertical"
> android:layout_width="fill_parent"
> android:layout_height="fill_parent"
> >
> <TextView
> android:layout_width="fill_parent"
> android:layout_height="wrap_content"
> android:text="Thanks for choosing our service"
> />
> <TextView
> android:layout_width="fill_parent"
> android:layout_height="wrap_content"
> android:text="Select the items you wish to buy"
> />
> <CheckBox
> android:id="@+id/check1"
> android:layout_width="wrap_content"
> android:layout_height="wrap_content"
> android:text="Item1" />
> <CheckBox
> android:id="@+id/check2"
> android:layout_width="wrap_content"
> android:layout_height="wrap_content"
> android:text="Item2" />
> <CheckBox
> android:id="@+id/check3"
> android:layout_width="wrap_content"
> android:layout_height="wrap_content"
> android:text="Item3" />
> <CheckBox
> android:id="@+id/check4"
> android:layout_width="wrap_content"
> android:layout_height="wrap_content"
> android:text="Item4" />
> <CheckBox
> android:id="@+id/check5"
> android:layout_width="wrap_content"
> android:layout_height="wrap_content"
> android:text="Item5" />
>
> <Button android:id="@+id/submit"
> android:layout_width="fill_parent"
> android:layout_height="wrap_content"
> android:text="Submit"
> />
>
> </LinearLayout>
>
> This is finally the code where the custom View will be created n
> displayed:
>
> -------------------------------------------------------------------------------------------------------------------------
> package hari.rts;
>
> import android.app.Activity;
> import android.content.Context;
> import android.graphics.Bitmap;
> import android.graphics.BitmapFactory;
> import android.graphics.Canvas;
> import android.graphics.Color;
> import android.graphics.Paint;
> import android.os.Bundle;
> import android.view.View;
> import android.widget.TextView;
>
> public class confirm extends Activity
> {
> String i,j,k,l,m;
> public void onCreate(Bundle savedInstanceState)
> {
> super.onCreate(savedInstanceState);
> setContentView(new MyView(this));
> i=getIntent().getExtras().getString("key1");
> j=getIntent().getExtras().getString("key2");
> k=getIntent().getExtras().getString("key3");
> l=getIntent().getExtras().getString("key4");
> m=getIntent().getExtras().getString("key5");
>
> }
> float getval1()
> {
> return 100;
> }
> float getval2()
> {
> return 200;
> }
> float getval3()
> {
> return 250;
> }
> float getval4()
> {
> return 300;
> }
> class MyView extends View
> {
> Paint paint = new Paint();
> Paint paint1=new Paint();
> float data1,data2,data3,data4;
> public MyView(Context context)
> {
> super(context);
> confirm activity = (confirm) context;
> data1 = activity.getval1();
> data2 = activity.getval2();
> data3 = activity.getval3();
> data4 = activity.getval4();
> paint.setColor(Color.RED);
> paint.setAlpha(255);
> paint.setStrokeWidth(3);
> paint1.setAlpha(230);
> }
> public void onDraw(Canvas canvas)
> {
> super.onDraw(canvas);
> canvas.drawLine(data1,data2,data3,data4, paint);
> //canvas.drawCircle(150, 200, 3, paint)
> Bitmap bit =
> BitmapFactory.decodeResource(getResources(),
> R.drawable.pic1);
> canvas.drawBitmap(bit,30,30,paint1);
> canvas.drawText(i,10,10,paint);
> canvas.drawText(j,20,10,paint);
> canvas.drawText(k,30,10,paint);
> canvas.drawText(l,40,10,paint);
> canvas.drawText(m,50,10,paint);
> }
> }
> }
>
> The problem now is where i should enter the layout for the custom
> View... If i give it in main.xml or details.xml,it crashes... If i
> create a new xml file n give it there, the application crashes when
> the custom view should be displayed... Please help me out with this
>
> --
> 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]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
--
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