i apologize in advance asking question out there, cannot seem work (i relatively new android studios).
i creating homework app takes user input through popup , user's input stored array of strings, converted adapter. adapter used print values of array user's screen through list view.
the issue having have 2 columns: 1 class name , 1 class assignment. able use 1 adapter display values class names, other column left default hint value. trying display both columns accordingly each of class names , respective assignments.
i know have somehow merge adapters one, not know how (see java planner). if please me out, appreciate greatly.
this java screen
package com.example.johnta.homeworkappv2; import android.app.listactivity; import android.content.intent; import android.os.bundle; import android.view.view; import android.widget.arrayadapter; import android.widget.edittext; import android.widget.linearlayout; import android.widget.listview; import android.widget.popupwindow; import android.widget.textview; import java.util.arraylist; import java.util.arrays; public class planneractivity extends listactivity { public static arraylist<string> arraylist, arraylist_assignments; private static arrayadapter<string> adapter, adapter_assignments; private static edittext txtinput; private static textview tvmsg; private static popupwindow popupwindow; private static linearlayout mainlayout; private string [] items = {"physics","humanities","math","stem"}; private string [] list_of_assignments = {"notes","reading","problems","engineering"}; private string [][] twodimensionalitems = {{"physics","notes"}}; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); popupwindow = new popupwindow(this); mainlayout = new linearlayout(this); setcontentview(r.layout.activity_planner); listview listview = (listview)findviewbyid(android.r.id.list); arraylist = new arraylist<>(arrays.aslist(items)); arraylist_assignments = new arraylist<>(arrays.aslist(list_of_assignments)); adapter = new arrayadapter<string>(this,r.layout.editlistitems,r.id.name_of_class,arraylist); adapter_assignments = new arrayadapter<string>(this,r.layout.editlistitems,r.id.homework_description,arraylist_assignments); listview.setadapter(adapter); txtinput = (edittext)findviewbyid(r.id.name_of_class); } public void makeeditable(view v) { } public void onclickedit (view v) { startactivity(new intent(planneractivity.this,popup.class)); } public static void additemtoarray (string itemtoadd) { arraylist.add(itemtoadd); adapter.notifydatasetchanged(); } }
this java popup
package com.example.johnta.homeworkappv2; import android.app.activity; import android.os.bundle; import android.util.displaymetrics; import android.view.view; import android.widget.edittext; /** * created johnta on 4/3/17. */ public class popup extends activity { private edittext txtinput; private edittext input_assignment; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.plannerpopup); displaymetrics dm = new displaymetrics(); getwindowmanager().getdefaultdisplay().getmetrics(dm); int width = dm.widthpixels; int height = dm.heightpixels; getwindow().setlayout((int)(width*0.8),(int)(height*0.6)); txtinput = (edittext)findviewbyid(r.id.name_of_class); input_assignment = (edittext)findviewbyid(r.id.class_assignment); } public void onclickeditlist (view v) { string newitem = txtinput.gettext().tostring(); planneractivity.additemtoarray(newitem); super.onbackpressed(); } }
**this xml activity_planner **
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.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="com.example.johnta.homeworkappv2.settings" android:background="#87ceeb"> <relativelayout android:layout_width="fill_parent" android:layout_height="fill_parent" app:layout_constraintleft_toleftof="parent" app:layout_constrainttop_totopof="parent" tools:layout_constraintleft_creator="1" tools:layout_constrainttop_creator="1"> <imageview android:id="@+id/planner_picture" android:layout_width="150dp" android:layout_height="150dp" android:layout_margintop="5dp" android:background="@drawable/roundbutton" app:srccompat="@drawable/planner10pad" android:layout_centerhorizontal="true" android:layout_marginbottom="35dp" /> <button android:id="@+id/edit_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="edit" tools:layout_editor_absolutex="16dp" tools:layout_editor_absolutey="130dp" android:layout_margintop="154dp" android:layout_alignparenttop="true" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:onclick="onclickedit"/> <button android:id="@+id/copy_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="copy" android:layout_alignbaseline="@+id/edit_button" android:layout_alignparentright="true" android:layout_alignparentend="true" android:layout_alignright="@id/planner_picture" /> <textview android:id="@+id/textview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="planner" android:textcolor="#000000" android:textsize="32sp" android:layout_aligntop="@+id/edit_button" android:gravity="center" android:layout_alignbottom="@+id/edit_button" android:layout_alignleft="@+id/planner_picture" android:layout_alignstart="@+id/planner_picture" android:layout_alignright="@+id/planner_picture" android:layout_alignend="@+id/planner_picture" /> <listview android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff" android:layout_below="@+id/edit_button" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:layout_weight="1" android:divider="#000000"> </listview> </relativelayout> </android.support.constraint.constraintlayout>
**this xml listview in planner **
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" > <textview android:id="@+id/name_of_class" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textsize="24sp" android:paddingtop="3dp" android:paddingbottom="3dp" android:paddingleft="5dp" android:paddingright="3dp" android:hint="class name" android:textstyle="bold" /> <textview android:id="@+id/homework_description" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingtop="3dp" android:paddingbottom="3dp" android:paddingleft="3dp" android:hint="class assignment" android:textsize="20sp" android:focusable="true" android:focusableintouchmode="true" android:inputtype="textmultiline" android:layout_alignbaseline="@+id/name_of_class" android:layout_alignbottom="@+id/name_of_class" android:layout_torightof="@+id/name_of_class" android:layout_toendof="@+id/name_of_class" /> </relativelayout>
the issue having have 2 columns: 1 class name , 1 class assignment. able use 1 adapter display values class names, other column left default hint value.
don't store 2 arraylists this.
you can either use hashmap , simpleadapter
or use oop features of java create custom arrayadapter plan
class hold's 2 strings (note class
reserved word in java).
might worth researching android databinding
Comments
Post a Comment