Professional Documents
Culture Documents
XML File :
<?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:id="@+id/activity_main"
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"
android:background="@color/colorBack"
tools:context="com.example.teqip3.ui_widgets.MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:layout_centerHorizontal="true"
android:src="@drawable/widget"/>
<TextView
android:id="@+id/textName"
android:layout_width="82dp"
android:layout_height="wrap_content"
android:text="Name:"
style="@style/CustomFontStyle"
android:layout_marginTop="8dp"
android:layout_below="@id/imageView"
android:layout_marginLeft="5dp"/>
<EditText
android:id="@+id/editTextName"
android:layout_toRightOf = "@+id/textName"
android:layout_marginLeft="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/imageView"
style="@style/CustomFontStyle"
android:hint="Simple EditText">
</EditText>
<TextView
android:id="@+id/textGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gender:"
style="@style/CustomFontStyle"
android:layout_marginTop="25dp"
android:layout_below="@id/textName"
android:layout_marginLeft="5dp"/>
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/textName"
android:layout_marginTop="22dp"
android:layout_toRightOf = "@+id/textGender"
android:layout_marginLeft="10dp">
<RadioButton
android:id="@+id/radioButtonMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
style="@style/CustomFontStyle"
android:text="Male" />
<RadioButton
android:id="@+id/radioButtonFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/CustomFontStyle"
android:text="Female" />
</RadioGroup>
<TextView
android:id="@+id/textCanSpeak"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Can Speak:"
style="@style/CustomFontStyle"
android:layout_below="@id/radioGroup1"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"/>
<CheckBox
android:id="@+id/checkBoxEnglish"
android:layout_toRightOf = "@+id/textCanSpeak"
android:layout_marginLeft="10dp"
android:layout_marginTop="6dp"
android:layout_width="match_parent"
android:layout_below="@id/radioGroup1"
android:layout_height="wrap_content"
style="@style/CustomFontStyle"
android:text="English" />
<CheckBox
android:id="@+id/checkBoxMarathi"
android:layout_toRightOf = "@+id/textCanSpeak"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/checkBoxEnglish"
android:layout_marginLeft="10dp"
style="@style/CustomFontStyle"
android:text="Marathi"/>
<CheckBox
android:id="@+id/checkBoxHindi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/checkBoxMarathi"
android:layout_toRightOf="@id/textCanSpeak"
android:layout_marginLeft="10dp"
style="@style/CustomFontStyle"
android:text="Hindi"/>
<TextView
android:id="@+id/textHostel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_below="@id/checkBoxHindi"
style="@style/CustomFontStyle"
android:layout_marginTop="15dp"/>
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="50dp"
android:layout_height="30dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="12dp"
android:layout_toRightOf="@id/textHostel"
android:layout_below="@id/checkBoxHindi"
android:background="@drawable/rounded_button"
android:textOff="No"
android:textOn="Yes"
android:textSize="16sp"
android:textColor="@color/colorAccent"
android:textStyle="bold"
android:text="ToggleButton"/>
<TextView
android:id="@+id/textAge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Age:"
android:layout_marginLeft="5dp"
android:layout_below="@id/textHostel"
style="@style/CustomFontStyle"
android:layout_marginTop="15dp"/>
<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@id/textAge"
android:layout_below="@id/toggleButton"/>
<TextView
android:id="@+id/textDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your Rating:"
android:layout_marginLeft="5dp"
android:layout_below="@id/seekBar"
style="@style/CustomFontStyle"
android:layout_marginTop="30dp"/>
<RatingBar
android:id="@+id/ratingBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/textDate"
android:layout_below="@id/seekBar"
android:layout_marginLeft="5dp"
android:layout_marginTop="15dp" />
<TextView
android:id="@+id/textCity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="City:"
android:layout_marginLeft="5dp"
android:layout_below="@id/ratingBar"
style="@style/CustomFontStyle"
android:layout_marginTop="5dp"/>
<ListView
android:id="@+id/Citylist"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@id/textCity"
android:divider="#f00"
android:dividerHeight="1dp"
android:textSize="8sp"
android:textStyle="bold"
android:background="@drawable/rounded_button"
android:listSelector="@color/colorPrimaryDark"
android:layout_below="@id/ratingBar"/>
<Button
android:id="@+id/btnSubmit"
android:text="Submit"
android:layout_width="80dp"
android:layout_height="25dp"
style="@android:style/Widget.Button"
android:background="@drawable/rounded_button"
android:textSize="16sp"
android:textColor="@color/colorAccent"
android:textStyle="bold"
android:layout_toRightOf="@id/textCity"
android:layout_below="@id/textCity"
android:layout_marginLeft="200dp"
android:layout_marginTop="100dp"
android:layout_marginBottom="0dp" />
</RelativeLayout>
rounded_button.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#ffffff"/>
<gradient
android:type="linear"
android:startColor="#FFffffff"
android:endColor="#FF008000"
android:angle="45"/>
</shape>
</item>
</selector>
strings.xml
<resources>
<string-array name="cities_array">
<item>Aurangabad</item>
<item>Pune</item>
<item>Nagpur</item>
<item>Mumbai</item>
<item>Hyderabad</item>
</string-array>
</resources>
styles.xml
<resources>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="CustomFontStyle">
<item name="android:typeface">serif</item>
<item name="android:textSize">15sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#990000</item>/>
</style>
</resources>
Java File :
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
import android.widget.SeekBar;
import android.widget.RatingBar;
import android.view.WindowManager;
String[] listItem;
String listItemValue;
Integer age;
StringBuilder result;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParam
s.FLAG_FULLSCREEN);
getSupportActionBar().hide();
toggleButtonNeedHostel = (ToggleButton)findViewById(R.id.toggleButton);
AgeSeekBar=(SeekBar)findViewById(R.id.seekBar);
ratingbar=(RatingBar)findViewById(R.id.ratingBar);
listView=(ListView)findViewById(R.id.Citylist);
//ListView
listItem = getResources().getStringArray(R.array.cities_array);
listView.setAdapter(adapter);
//Listview listener
listView.setOnItemClickListener(new AdapterView.OnItemClickListener()
@Override
long l)
listItemValue=adapter.getItem(position);
Toast.makeText(getApplicationContext(),listItemValue,Toast.LENGTH_SHORT).show();
});
btnSubmit.setOnClickListener(new View.OnClickListener()
@Override
result.append(nameTextBox.getText()+"\n");
if(checkboxEnglish.isChecked())
result.append(checkboxEnglish.getText()+" ");
if(checkboxMarathi.isChecked())
result.append(checkboxMarathi.getText()+" ");
if(checkboxHindi.isChecked())
result.append(checkboxHindi.getText()+" ");
").append(toggleButtonNeedHostel.getText());
//Get age
result.append("\nAge:" + String.valueOf(age));
Toast.makeText(getApplicationContext(), result.toString(),
Toast.LENGTH_LONG).show();
});
//Seekbar Listener
AgeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
@Override
boolean fromUser) {
Toast.LENGTH_SHORT).show();
age = progress;
@Override
@Override
});
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.dell.smssendingapp">
<uses-permission android:name="android.permission.SEND_SMS"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
</intent-filter>
</activity>
</application>
</manifest>
Outputs :
Result :
Hence, we have created an android application with UI controls/Widgets
with event handling.