Populating ListViews for Event type and sub-type, but can't get the selected one to highlight. Will change to use spinners instead.

This commit is contained in:
Graham Jones
2022-01-17 18:34:49 +00:00
parent 1c20387753
commit ff9bb06241
4 changed files with 97 additions and 8 deletions

View File

@@ -8,6 +8,7 @@ import android.os.Handler;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.AbsListView;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
@@ -23,6 +24,7 @@ import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@@ -37,6 +39,12 @@ public class EditEventActivity extends AppCompatActivity
private OsdUtil mUtil; private OsdUtil mUtil;
private List<String> mEventTypesList = null; private List<String> mEventTypesList = null;
private HashMap<String, ArrayList<String>> mEventSubTypesHashMap = null; private HashMap<String, ArrayList<String>> mEventSubTypesHashMap = null;
private String mEventTypeStr = null;
private String mEventSubTypeStr = null;
private Long mEventId;
private String mEventNotes = "";
private Date mEventDateTime;
@Override @Override
@@ -57,8 +65,12 @@ public class EditEventActivity extends AppCompatActivity
Button OKBtn = (Button) findViewById(R.id.OKBtn); Button OKBtn = (Button) findViewById(R.id.OKBtn);
OKBtn.setOnClickListener(onOK); OKBtn.setOnClickListener(onOK);
ListView lv = (ListView) findViewById(R.id.eventTypeLv); ListView lv;
lv = (ListView) findViewById(R.id.eventTypeLv);
lv.setOnItemClickListener(onEventTypeClick); lv.setOnItemClickListener(onEventTypeClick);
lv = (ListView) findViewById(R.id.eventSubTypeLv);
lv.setOnItemClickListener(onEventSubTypeClick);
mWac = new WebApiConnection(this, this, this, this); mWac = new WebApiConnection(this, this, this, this);
mLm = new LogManager(this); mLm = new LogManager(this);
@@ -118,15 +130,40 @@ public class EditEventActivity extends AppCompatActivity
private void updateUi() { private void updateUi() {
Log.v(TAG, "updateUI"); Log.v(TAG, "updateUI");
if (mEventTypesList != null) { TextView tv;
//TextView tv = (TextView) findViewById(R.id.tokenTv); // tv = (TextView) findViewById(R.id.tokenTv);
//tv.setText("Logged in with Token:" + storedAuthToken); //tv.setText("Logged in with Token:" + storedAuthToken);
if (mEventTypesList != null) {
Log.v(TAG, "updateUi: " + mEventTypesList.toString()); Log.v(TAG, "updateUi: " + mEventTypesList.toString());
ListView lv = (ListView) findViewById(R.id.eventTypeLv); ListView lv = (ListView) findViewById(R.id.eventTypeLv);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.event_type_list_item, R.id.eventTypeTv, mEventTypesList); R.layout.event_type_list_item, R.id.eventTypeTv, mEventTypesList);
lv.setAdapter(adapter); lv.setAdapter(adapter);
} }
if (mEventSubTypesHashMap != null) {
if (mEventTypeStr != null) {
// based on https://androidexample.com/create-a-simple-listview
ArrayList<String> subtypesArrayList = mEventSubTypesHashMap.get(mEventTypeStr);
Log.v(TAG, "setSubtypesLV - eventType=" + mEventTypeStr + ", subtypes=" + subtypesArrayList);
ListView lv = (ListView) findViewById(R.id.eventSubTypeLv);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.event_sub_type_list_item, R.id.eventSubTypeTv, subtypesArrayList);
lv.setAdapter(adapter);
}
}
tv = (TextView)findViewById(R.id.eventTypeTv);
if (mEventTypeStr != null) {
tv.setText(mEventTypeStr);
} else {
tv.setText(R.string.selectFromOptionselow);
}
tv = (TextView)findViewById(R.id.eventSubTypeTv);
if (mEventSubTypeStr != null) {
tv.setText(mEventSubTypeStr);
} else {
tv.setText(R.string.selectFromOptionselow);
}
} }
View.OnClickListener onCancel = View.OnClickListener onCancel =
@@ -154,11 +191,12 @@ public class EditEventActivity extends AppCompatActivity
}; };
private void setSubTypesLV(String eventType) { private void setSubTypesLV(String eventType) {
// based on https://androidexample.com/create-a-simple-listview
ArrayList<String> subtypesArrayList = mEventSubTypesHashMap.get(eventType); ArrayList<String> subtypesArrayList = mEventSubTypesHashMap.get(eventType);
Log.v(TAG,"setSubtypesLV - eventType="+eventType+", subtypes="+subtypesArrayList); Log.v(TAG,"setSubtypesLV - eventType="+eventType+", subtypes="+subtypesArrayList);
ListView lv = (ListView)findViewById(R.id.eventSubTypeLv); ListView lv = (ListView)findViewById(R.id.eventSubTypeLv);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.event_sub_type_list_item, R.id.eventSubTypeLv, subtypesArrayList); R.layout.event_sub_type_list_item, R.id.eventSubTypeTv, subtypesArrayList);
lv.setAdapter(adapter); lv.setAdapter(adapter);
} }
@@ -166,9 +204,22 @@ public class EditEventActivity extends AppCompatActivity
new AdapterView.OnItemClickListener() { new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> adapter, View v, int position, long id) { public void onItemClick(AdapterView<?> adapter, View v, int position, long id) {
Log.v(TAG, "onEventTypeClick() - Position=" + position + ", id=" + id);// Confirmation dialog based on: https://stackoverflow.com/a/12213536/2104584 Log.v(TAG, "onEventTypeClick() - Position=" + position + ", id=" + id);// Confirmation dialog based on: https://stackoverflow.com/a/12213536/2104584
String selectedEventType = (String) adapter.getItemAtPosition(position); mEventTypeStr = (String) adapter.getItemAtPosition(position);
Log.v(TAG,"onEventTypeClick - selected "+selectedEventType); Log.v(TAG,"onEventTypeClick - selected "+mEventTypeStr);
setSubTypesLV(selectedEventType); updateUi();
//setSubTypesLV(selectedEventType);
} }
}; };
AdapterView.OnItemClickListener onEventSubTypeClick =
new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> adapter, View v, int position, long id) {
Log.v(TAG, "onEventSubTypeClick() - Position=" + position + ", id=" + id);// Confirmation dialog based on: https://stackoverflow.com/a/12213536/2104584
mEventSubTypeStr = (String) adapter.getItemAtPosition(position);
Log.v(TAG,"onEventSubTypeClick - selected "+mEventSubTypeStr);
updateUi();
//setSubTypesLV(selectedEventType);
}
};
} }

View File

@@ -32,11 +32,45 @@
android:text="[id]" /> android:text="[id]" />
</LinearLayout> </LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="@string/event_type" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="event_type"
android:id="@+id/eventTypeTv"/>
</LinearLayout>
<ListView <ListView
android:id="@+id/eventTypeLv" android:id="@+id/eventTypeLv"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="150dp" android:layout_height="150dp"
android:layout_marginTop="10dp" /> android:layout_marginTop="0dp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="@string/event_sub_type" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="event_sub_type"
android:textSize="20sp"
android:id="@+id/eventSubTypeTv"/>
</LinearLayout>
<ListView <ListView
android:id="@+id/eventSubTypeLv" android:id="@+id/eventSubTypeLv"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@@ -5,6 +5,7 @@
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textSize="20sp"
android:text="eventType" android:text="eventType"
android:id="@+id/eventTypeTv" /> android:id="@+id/eventTypeTv" />
</LinearLayout> </LinearLayout>

View File

@@ -320,4 +320,7 @@
<string name="remoteLogPeriodTitle">Remote Log Period (seconds)</string> <string name="remoteLogPeriodTitle">Remote Log Period (seconds)</string>
<string name="ManualAlarmBtnTxt">Raise Alarm</string> <string name="ManualAlarmBtnTxt">Raise Alarm</string>
<string name="save">Save</string> <string name="save">Save</string>
<string name="event_type">Event Type:</string>
<string name="event_sub_type">"Event Sub-Type: "</string>
<string name="selectFromOptionselow"><![CDATA[<Select from Options Below>]]></string>
</resources> </resources>