Skip to main content

Add Auto Complete Textview To Your App

Add AutoCompleteTextview To Your App



1)Navigate to activity_main.xml .You have to add some code here. Watch the above  video for reference .
After adding the code, your activity_main.xml will look like this:


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">


    <AutoCompleteTextView
        android:id="@+id/autocompleteView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:hint="Enter Your Favourite Color" />


    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="Submit"
        android:textAllCaps="false"
        android:textColor="#ffffff"
        android:theme="@style/MyButton" />

</RelativeLayout>


2)Modify the styles.xml as follows


<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="colorButtonNormal">@color/colorButtonNormal</item>
    </style>





    <style name="MyButton" parent="Theme.AppCompat.Light">
        <item name="colorButtonNormal">@color/colorButtonNormal</item>
        <item name="colorControlHighlight">@color/colorPrimaryDark</item>

    </style>


</resources>


3) Now Open strings.xml and make the changes as follows


<resources>
    <string name="app_name">SketchLogicApp</string>
    <string-array name="color_list">
        <item>Red</item>
        <item>Blue</item>
        <item>Green</item>
        <item>White</item>
        <item>Black</item>
        <item>Yellow</item>
        <item>Orange</item>
        <item>Brown</item>
    </string-array>
</resources>


4) Next , Open colors.xml and make the changes as follows


<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>
    <color name="colorButtonNormal">#2889ff</color>
</resources>



5) After making all these changes ,navigate to MainActivity.java and make the some changes.Your           MainActivity.java file will look like this after making the changes


import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import java.util.Arrays;
import java.util.List;

public class MainActivity extends AppCompatActivity {



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        int layoutItemId = android.R.layout.simple_dropdown_item_1line;
        String[] color_list = getResources().getStringArray(R.array.color_list);
        List<String> color = Arrays.asList(color_list);
        ArrayAdapter<String> adapter = new ArrayAdapter<>(this, layoutItemId, color_list);

        AutoCompleteTextView autocompleteView =
                (AutoCompleteTextView) findViewById(R.id.autocompleteView);
        autocompleteView.setAdapter(adapter);








    }
}


6) Now Run and test your app on your real device or emulator.
   If you get errors ,comment below


Comments

  1. How to change sketchware project to android studio.

    ReplyDelete

Post a Comment

Did you like this tutorial ?

Popular posts from this blog

Add Edittext Inside Dialog Box

Add Edittext Inside Dialog Box If you haven`t yet watched the video... Watch  it right  now!!! The code used in the above video is available here. final EditText edittext1= new EditText(MainActivity.this); LinearLayout.LayoutParams lpar = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); edittext1.setLayoutParams(lpar); dialog.setView(edittext1); textview1.setText(edittext1.getText());

Create Custom Popup Window using Sketchware

Create Custom Popup Window using Sketchware Refer the video below if  you get stuck.  1) Add a custom view named window.You can name it according to your wish.  2)Design your popup window.  2) Now, In the logic section,In OnCLick event of button.Add the following  code Create a view View popupView = getLayoutInflater().inflate(R.layout.window, null); Popup window  final PopupWindow popup = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true); Initialize  Button b1 = popupView.findViewById(R.id.button1); Button b2 = popupView.findViewById(R.id.button2); OnClickListeners b1.setOnClickListener(new OnClickListener() { public void onClick(View view) { //below code will dismiss the popup window popup.dismiss(); } }); b2.setOnClickListener(new OnClickListener() { public void onClick(View view) { popup.dismiss(); } }); Show the popup window  popup.showAtLoc