Question: Subject: Smart Phone Application Development Question: Explore the dictionary project. Add various word and its meaning. Try to use constraint layout instead of linear layout

Subject: Smart Phone Application Development

Question: Explore the dictionary project. Add various word and its meaning. Try to use constraint layout instead of linear layout in view?

For WordDataModel.java class,

packagecom.example.dictionary; importjava.util.ArrayList; importjava.util.List; public classWordDataModel { publicStringenglish; publicStringbangla; publicWordDataModel(String english, String bangla) { this.english= english; this.bangla= bangla; } publicString getEnglish() { returnenglish; } publicWordDataModel setEnglish(String english) { this.english= english; return this; } publicString getBangla() { returnbangla; } publicWordDataModel setBangla(String bangla) { this.bangla= bangla; return this; } public staticList getDataList() { ArrayList dictionary =newArrayList<>(); dictionary.add(newWordDataModel("Book", "")); dictionary.add(newWordDataModel("School", "")); dictionary.add(newWordDataModel("University", "")); dictionary.add(newWordDataModel("Exercise", "")); dictionary.add(newWordDataModel("Home", "")); dictionary.add(newWordDataModel("Work", "")); dictionary.add(newWordDataModel("Practical", "")); dictionary.add(newWordDataModel("Pen", "")); dictionary.add(newWordDataModel("Rice", "")); dictionary.add(newWordDataModel("News", "")); dictionary.add(newWordDataModel("Newspaper", "")); returndictionary; } }

For MainActivity.java class,

packagecom.example.dictionary; importandroidx.appcompat.app.AppCompatActivity; importandroidx.recyclerview.widget.DefaultItemAnimator; importandroidx.recyclerview.widget.DividerItemDecoration; importandroidx.recyclerview.widget.LinearLayoutManager; importandroidx.recyclerview.widget.RecyclerView; importandroid.os.Bundle; importandroid.util.Log; importjava.util.List; public classMainActivityextendsAppCompatActivity { private finalStringLOG_TAG="DICTIONARY"; @Override protected voidonCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); RecyclerView wordsHolder = findViewById(R.id.wordsHolder); List words = WordDataModel.getDataList(); DictionaryAdapter dictionaryAdapter =newDictionaryAdapter(words); wordsHolder.setAdapter(dictionaryAdapter); LinearLayoutManager layoutManager = new LinearLayoutManager(this); wordsHolder.setLayoutManager(layoutManager); DividerItemDecoration dividerItemDecoration =newDividerItemDecoration(wordsHolder.getContext(), layoutManager.getOrientation()); wordsHolder.addItemDecoration(dividerItemDecoration); Log.v(LOG_TAG,"On Create Called"); } @Override protected voidonStart() { super.onStart(); Log.d(LOG_TAG,"On Start Called"); } @Override protected voidonStop() { super.onStop(); Log.d(LOG_TAG,"On Stop Called"); } @Override protected voidonResume() { super.onResume(); Log.d(LOG_TAG,"On Resume Called"); } @Override protected voidonPause() { super.onPause(); Log.d(LOG_TAG,"On Pause Called"); } @Override protected voidonDestroy() { super.onDestroy(); Log.d(LOG_TAG,"On Destroy Called"); } }

For Dictionary.adapter.java class,

packagecom.example.dictionary; importandroid.content.Context; importandroid.view.LayoutInflater; importandroid.view.View; importandroid.view.ViewGroup; importandroid.widget.TextView; importandroidx.recyclerview.widget.RecyclerView; importjava.util.List; public classDictionaryAdapterextends RecyclerView.Adapter { privateList wordCollections; publicDictionaryAdapter(List wordCollections) { this.wordCollections= wordCollections; } @Override publicViewHolder onCreateViewHolder(ViewGroup parent,int viewType) { Context context = parent.getContext(); LayoutInflater inflater = LayoutInflater.from(context); View contactView = inflater.inflate(R.layout.dictionary_item, parent,false); return newViewHolder(contactView); } @Override public voidonBindViewHolder(DictionaryAdapter.ViewHolder holder,intposition) { WordDataModel wordDataModel =wordCollections.get(position); holder.englishWord.setText(wordDataModel.english); holder.banglaWord.setText(wordDataModel.bangla); } @Override public intgetItemCount() { returnwordCollections.size(); } public classViewHolder extendsRecyclerView.ViewHolder { publicTextViewenglishWord; publicTextViewbanglaWord; publicViewHolder(View itemView) { super(itemView); englishWord= itemView.findViewById(R.id.englishWord); banglaWord= itemView.findViewById(R.id.banglaWord); } } }

For activity_main.xml,

xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout 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" tools:context=".MainActivity"> <androidx.recyclerview.widget.RecyclerView android:id="@+id/wordsHolder" android:layout_width="0dp" android:layout_height="0dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"/> androidx.constraintlayout.widget.ConstraintLayout>

For dictionary_item.xml,

xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/englishWord" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="English Word" android:textSize="34sp"/> <TextView android:id="@+id/banglaWord" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:paddingBottom="15dp" android:text="Bangla Word" android:textSize="34sp"/> LinearLayout>

For AndroidManifest.xml, xml version="1.0"encoding="utf-8"?> <manifestxmlns:android="http://schemas.android.com/apk/res/android" package="com.example.dictionary"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" a.."@style/Theme.Dictionary"> <activity android:name=".MainActivity" android:exported="true"> <intent-filter> <actionandroid:name="android.intent.action.MAIN"/> <categoryandroid:name="android.intent.category.LAUNCHER"/> intent-filter> activity> application> manifest>

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!