Friday, 8 July 2016
Saturday, 2 July 2016
Friday, 1 July 2016
Simple Name print in toast
Hello ____
activity_hello.xml
<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="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Helloworld" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="15dp"
android:layout_marginTop="112dp"
android:text="@string/lname"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView1"
android:layout_marginLeft="32dp"
android:layout_toRightOf="@+id/textView1"
android:ems="10"
android:inputType="text"
>
<requestFocus />
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/textView1"
android:text="@string/btnshow" />
</RelativeLayout>
Hello.java
package first.program;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class Helloworld extends Activity {
private TextView lblname;
EditText name;
Button show;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_helloworld);
lblname=(TextView)findViewById(R.id.textView1);
name=(EditText)findViewById(R.id.editText1);
show=(Button)findViewById(R.id.button1);
//set listener on button
show.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Hello "+name.getText().toString(), Toast.LENGTH_LONG).show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.hello, menu);
return true;
}
}
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class Helloworld extends Activity {
private TextView lblname;
EditText name;
Button show;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_helloworld);
lblname=(TextView)findViewById(R.id.textView1);
name=(EditText)findViewById(R.id.editText1);
show=(Button)findViewById(R.id.button1);
//set listener on button
show.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Hello "+name.getText().toString(), Toast.LENGTH_LONG).show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.hello, menu);
return true;
}
}
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">helloworld</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="lname">Name</string>
<string name="btnshow">Show</string>
</resources>
<resources>
<string name="app_name">helloworld</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="lname">Name</string>
<string name="btnshow">Show</string>
</resources>
Subscribe to:
Posts (Atom)