Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given codes Modify the program so that - When any item is selected, SAVE button text changes from SAVE to UPDATE - After UPDATE button

image text in transcribed

Given codes

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Modify the program so that - When any item is selected, SAVE button text changes from SAVE to UPDATE - After UPDATE button is clicked, UPDATE text is changed to SAVE again. Xmi version = "1.0" encoding = "utf-8"? Indroidx. constraintlayout.widget. ConstraintLayout xmlns: android="http://schemas. android. com/apk/res/androic xmins:app="http://schenas. 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" > > id= " [i+1d/ et " android:layout_width="match_parent" android: Layout_height="wrap_content" android: ems=" 10" android:inputType = "textPersonName" android: hint = "Name" android:textSize=" 24sp"> LListView android:id=" 0+id/2v110 android:layout_width = "match_parent" android:layout_height="match_parent" /> Linearlayout > constraintlayout.widget. Constraintlayout> MyListAdapter.jova k?xnl version= " 1.0" encoding = "utf 8n?> 10n android: descendantFocusability= "blocksDescendants" = " 50dp " android:layout_height=" 50dp " android:Zayout_weight= "1" android:padding = " 5dp " app:srcCompat="@android:drawable/btn_star_big_on" /> = "false" /> ckage con port ... gages blic class MainActivity extends AppCompatActivity \{ 4 usages Integer selected_pos =1;//1 means nothing is selected I/ array of season 1 usage String[] s1 = \{"Spring", "Summer", "Autumn", "Winter" }; II array of dravable 1 usage Integer [] c1 = \{android.R.dravable.btn_star_big_off, android.R.drawable.btn_star_big_on, android.R.drawable.btn_radio, android.R.drawable.ic_dialog_email\}; I/ convert array into arraylist 3 usages ArrayList Strings season = new ArrayList ( Arrays. asList (S1)); 2 usages ArrayList> icon = new ArrayList > (Arrays.asList (c1)); I/ define object variables 3 usages ListView lv1; Button btn_add; 4 usages EditText et1; (a0verride protected void oncreate(Bundle savedinstancestate) \{ super. oncreate (savedinstancestate); setContentView(R. Layout.activity_main); Log.d( tag: "Louis", String.value0f(R.layout.activity_main)); Log.i( tag: "Louis", msg: "This is line 151" ); et 1 = findViewById(R.id.et 1); lv1 = findviewById ( R.id. 2v1); MyListAdapter adapter=new MyListAdapter( context: this, season, icon); Lv1.setAdapter(adapter); Zv1.setonItemClickListener(new AdapterView. OnItemclickListener () f (c) MyListAdapterjava activity_listview.xml activity_main ml MyListadapter adapter=new MyListAdapter( context this, season, icon); Zv1.setAdapter (adapter); Zv1.setonItemClickListener (new AdapterView. OnItemclickListener () \{ @0verride public void onItemClick(AdapterView parent, View view, int position, long id) \{ String selected = (String) parent.getItemAtPosition(position); Toast.makeText(getApplicationContext(), text: String. valueof (position)+": "+selected, Toast.LENGTH_LONG). Show(); Log. d( tag: "Louis check", msg: String.valueof(position) + ": "+selected); selected_pos = position; /1 remember which item is selected et1. setText(selected); // show selected season to edittext \}); Button btn_add; btn_add = findViewById(R.id.btn_add ; btn_add.setText(tisavet i ; btn_add.setonclickListener(new View.OnclickListener () \{ @override public void onclick(View v) \{ if (selected_pos =1 ) {// means nothing selected to update I/ then new item is added season.add(et1, getText(), tostring()); icon.add (android.R.drawable.ic_dialog_map); f else \& Il something is selected to ydpate //e.g. season.set( 1, "haha" ); // replace summer season.set(selected_pos, et1.getText().tostring()); selected_pos =1;// reset to nothing selected \} adapter. notifyDatasetChanged(); InputMethodManager imm= (InputMethodManager) getSystemService(context._NPUT_METHOD_SER imm.hidesoftinputFromWindow (v.getWindowToken(), flags 0); \} 3); ic class |lyListAdapter extends ArrayAdapter \{ //implements .... 2 usages private final Activity context; 3 usages private final ArrayList> season; 2 usages private final ArrayList > id= " [i+1d/ et " android:layout_width="match_parent" android: Layout_height="wrap_content" android: ems=" 10" android:inputType = "textPersonName" android: hint = "Name" android:textSize=" 24sp"> LListView android:id=" 0+id/2v110 android:layout_width = "match_parent" android:layout_height="match_parent" /> Linearlayout > constraintlayout.widget. Constraintlayout> MyListAdapter.jova k?xnl version= " 1.0" encoding = "utf 8n?> 10n android: descendantFocusability= "blocksDescendants" = " 50dp " android:layout_height=" 50dp " android:Zayout_weight= "1" android:padding = " 5dp " app:srcCompat="@android:drawable/btn_star_big_on" /> = "false" /> ckage con port ... gages blic class MainActivity extends AppCompatActivity \{ 4 usages Integer selected_pos =1;//1 means nothing is selected I/ array of season 1 usage String[] s1 = \{"Spring", "Summer", "Autumn", "Winter" }; II array of dravable 1 usage Integer [] c1 = \{android.R.dravable.btn_star_big_off, android.R.drawable.btn_star_big_on, android.R.drawable.btn_radio, android.R.drawable.ic_dialog_email\}; I/ convert array into arraylist 3 usages ArrayList Strings season = new ArrayList ( Arrays. asList (S1)); 2 usages ArrayList> icon = new ArrayList > (Arrays.asList (c1)); I/ define object variables 3 usages ListView lv1; Button btn_add; 4 usages EditText et1; (a0verride protected void oncreate(Bundle savedinstancestate) \{ super. oncreate (savedinstancestate); setContentView(R. Layout.activity_main); Log.d( tag: "Louis", String.value0f(R.layout.activity_main)); Log.i( tag: "Louis", msg: "This is line 151" ); et 1 = findViewById(R.id.et 1); lv1 = findviewById ( R.id. 2v1); MyListAdapter adapter=new MyListAdapter( context: this, season, icon); Lv1.setAdapter(adapter); Zv1.setonItemClickListener(new AdapterView. OnItemclickListener () f (c) MyListAdapterjava activity_listview.xml activity_main ml MyListadapter adapter=new MyListAdapter( context this, season, icon); Zv1.setAdapter (adapter); Zv1.setonItemClickListener (new AdapterView. OnItemclickListener () \{ @0verride public void onItemClick(AdapterView parent, View view, int position, long id) \{ String selected = (String) parent.getItemAtPosition(position); Toast.makeText(getApplicationContext(), text: String. valueof (position)+": "+selected, Toast.LENGTH_LONG). Show(); Log. d( tag: "Louis check", msg: String.valueof(position) + ": "+selected); selected_pos = position; /1 remember which item is selected et1. setText(selected); // show selected season to edittext \}); Button btn_add; btn_add = findViewById(R.id.btn_add ; btn_add.setText(tisavet i ; btn_add.setonclickListener(new View.OnclickListener () \{ @override public void onclick(View v) \{ if (selected_pos =1 ) {// means nothing selected to update I/ then new item is added season.add(et1, getText(), tostring()); icon.add (android.R.drawable.ic_dialog_map); f else \& Il something is selected to ydpate //e.g. season.set( 1, "haha" ); // replace summer season.set(selected_pos, et1.getText().tostring()); selected_pos =1;// reset to nothing selected \} adapter. notifyDatasetChanged(); InputMethodManager imm= (InputMethodManager) getSystemService(context._NPUT_METHOD_SER imm.hidesoftinputFromWindow (v.getWindowToken(), flags 0); \} 3); ic class |lyListAdapter extends ArrayAdapter \{ //implements .... 2 usages private final Activity context; 3 usages private final ArrayList> season; 2 usages private final ArrayList

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions