0% found this document useful (0 votes)
3 views

Practical 8 code

The document contains two Android layout XML files and their corresponding Java activity classes. The first layout allows users to select a search engine from an AutoCompleteTextView and submit their choice, while the second layout enables users to select multiple subjects from a list. Both activities display the selected options upon clicking the submit button.

Uploaded by

anujkothawale93
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Practical 8 code

The document contains two Android layout XML files and their corresponding Java activity classes. The first layout allows users to select a search engine from an AutoCompleteTextView and submit their choice, while the second layout enables users to select multiple subjects from a list. Both activities display the selected options upon clicking the submit button.

Uploaded by

anujkothawale93
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1:-

<?xml version="1.0" encoding="utf-8" ?>


<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_margin="10sp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/SearchEngine"/>

<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/SearchEngine"
android:hint="@string/SearchEngine"
android:completionThreshold="1"/>

</LinearLayout>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Submit"
android:id="@+id/Submit"
android:layout_gravity="center"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/Display"
android:text=""
android:layout_gravity="center"
android:textStyle="bold"
android:textSize="30sp"
android:textColor="@color/black"/>

</LinearLayout>
package com.example.edit;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class MainActivity extends Activity {


String[] searchEngine ={"Google", "Microsoft Bing", "Yahoo", "DuckDuckGo"};

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

ArrayAdapter<String> adp =new ArrayAdapter<String>(this,


android.R.layout.simple_dropdown_item_1line, searchEngine);
AutoCompleteTextView textView=(AutoCompleteTextView)
findViewById(R.id.SearchEngine);
textView.setAdapter(adp);
textView.setThreshold(1);

Button submit=findViewById(R.id.Submit);
TextView display=findViewById(R.id.Display);

submit.setOnClickListener(v->{
String SearchEngine=textView.getText().toString();
display.setText(getString(R.string.Display,SearchEngine));
}
);

}
}

2:-
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_margin="10sp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Sem"/>

<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/Sub1"
android:hint="@string/Sub1"
android:completionThreshold="1"/>

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Sem"/>

<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/Sub2"
android:hint="@string/Sub2"
android:completionThreshold="1"/>

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Sem"/>

<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/Sub3"
android:hint="@string/Sub3"
android:completionThreshold="1"/>

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Sem"/>

<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/Sub4"
android:hint="@string/Sub4"
android:completionThreshold="1"/>

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Sem"/>

<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/Sub5"
android:hint="@string/Sub5"
android:completionThreshold="1"/>

</LinearLayout>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Submit"
android:id="@+id/Submit"
android:layout_gravity="center"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/Display"
android:text=""
android:layout_gravity="center"
android:textSize="25sp"
android:textColor="@color/black"/>

</LinearLayout>

package com.example.edit;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class MainActivity extends Activity {


String[] subjects ={"Mobile Application Development", "Network and Information
Security", "Advanced Algorithms in AI & ML", "Big Data Analytics", "Management"};

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

ArrayAdapter<String> adp =new ArrayAdapter<String>(this,


android.R.layout.simple_dropdown_item_1line, subjects);
AutoCompleteTextView sub1=(AutoCompleteTextView) findViewById(R.id.Sub1);
AutoCompleteTextView sub2=(AutoCompleteTextView) findViewById(R.id.Sub2);
AutoCompleteTextView sub3=(AutoCompleteTextView) findViewById(R.id.Sub3);
AutoCompleteTextView sub4=(AutoCompleteTextView) findViewById(R.id.Sub4);
AutoCompleteTextView sub5=(AutoCompleteTextView) findViewById(R.id.Sub5);

sub1.setAdapter(adp);
sub1.setThreshold(1);
sub2.setAdapter(adp);
sub2.setThreshold(1);
sub3.setAdapter(adp);
sub3.setThreshold(1);
sub4.setAdapter(adp);
sub4.setThreshold(1);
sub5.setAdapter(adp);
sub5.setThreshold(1);

Button submit=findViewById(R.id.Submit);
TextView display=findViewById(R.id.Display);

submit.setOnClickListener(v->{
String Sub1=sub1.getText().toString();
String Sub2=sub2.getText().toString();
String Sub3=sub3.getText().toString();
String Sub4=sub4.getText().toString();
String Sub5=sub5.getText().toString();

display.setText(getString(R.string.Display,Sub1,Sub2,Sub3,Sub4,Sub5));
}
);

}
}

You might also like