Combining both view with xml layout


Combining both view with xml layout.



package com.android.murthy;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.EditText;

public class Dynamic extends Activity {
/** Called when the activity is first created. */
Inner inner;
EditText preview_val;
Button show_prev;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
inner = new Inner(this);
// setContentView(inner);
LayoutParams params = new LayoutParams(150,105);
addContentView(inner, params);
preview_val = (EditText) findViewById(R.id.prev_value);
show_prev = (Button) findViewById(R.id.previewBtn);
show_prev.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String value = preview_val.getText().toString();
Log.i("edit_txt value",value);
}
});




}
private class Inner extends View{

public Inner(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
Rect rect = new Rect(10, 40, 60, 80);
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.RED);
// canvas.drawColor(Color.GREEN);
canvas.drawRect(rect, paint);
}
}
}
main.xml

android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"

>


android:layout_height="fill_parent" >

android:layout_marginLeft="200dp"
android:text="ZOOM (%)"
android:id="@+id/zoom_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"/>

android:id="@+id/prev_value"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="200dp"
android:maxLines="1"/>


Comments

Popular posts from this blog

Android Objective type Question and Answers

Android Questions and Answers for written exams

SCJP1.6 Question and Answers