• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with MyView extends View and main activity file

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q 1. What should I use to access from main_activity to custom_view activity?

Q 2. Is there any relation between a layout and the click event?

Q 3. Do I need to write setContentView in MyView constructor?

I need to use View class in this program

MainActivity

package com.easyway2win;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;


public class MainActivity extends Activity {

//Button bpink;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent= new Intent(MainActivity.this,MyView.class);
startActivity(intent);

}

}


MyView

package com.easyway2win;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;

public class MyView extends View implements OnClickListener{

public MyView(Context context) {
super(context);

bpink = (Button)findViewById(R.id.pinkColor);
bpink.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
Log.d("Hi","Hello");
}
});

myview_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/mytxtId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mytext" />

<Button
android:id="@+id/pinkColor"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_alignParentLeft="true"
android:layout_below="@id/mytxtId"
android:background="@drawable/pinkcolor"
android:text="Submit" />

<Button
android:id="@+id/blueColor"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_below="@id/mytxtId"
android:layout_toRightOf="@id/pinkColor"
android:background="@drawable/bluecolor" />

</RelativeLayout>
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
aimesh Vyas]Q 1. What should I use to access from main_activity to custom_view activity?

Q 2. Is there any relation between a layout and the click event?

Q 3. Do I need to write setContentView in MyView constructor?

I need to use View class in this program

MainActivity



MyView


myview_activity.xml
 
He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic