Moving from a SimpleAdapter to an ArrayAdaptor generates following exception:
java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView
Based on research, some .XML file is wrong, tried several variations unsuccessfully:
Here is the m_list_layout.XML
The offending bit of Java, apparently I cannot have more than 2 TextViews and they must be TextViews. That's just as unacceptable as the SimpleAdaptor...
UPDATE12/7/17 4:17
Aww, gee, do I have to customize an ArrayAdaptor? Is there a less intensive way of doing it?
java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView
Based on research, some .XML file is wrong, tried several variations unsuccessfully:
Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.test.MainActivity">
<TextView
android:id="@+id/test123"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Testing 123 Title"/>
<TextView
android:id="@+id/pgroup"
android:layout_width="110dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_below="@+id/test123"
android:layout_marginTop="12dp"
android:textSize="20dip"
android:textStyle="bold"
android:text="PGroup"/>
<Button
android:id="@+id/button_A"
android:layout_marginTop="25dp"
android:layout_toRightOf="@+id/pgroup"
android:layout_width="130dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textSize="15dip"
android:textStyle="bold"
android:text="A Data"/>
<Button
android:id="@+id/button_B"
android:layout_marginTop="25dp"
android:layout_toRightOf="@+id/button_A"
android:layout_marginLeft="5dp"
android:layout_width="130dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textSize="15dip"
android:textStyle="bold"
android:text="B Data" />
<ListView
android:id="@+id/mlist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/pgroup"
android:layout_marginTop="20dp"
android:gravity="center" />
</RelativeLayout>
Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="@dimen/activity_horizontal_margin">
<!-- Body -->
<TextView
android:id="@+id/tv_pcode"
android:layout_width="40dp"
android:layout_height="16dp"
android:layout_alignParentLeft="true"
android:gravity="left"
android:textAppearance="?android:textAppearanceSmall"
android:text="p" />
<TextView
android:id="@+id/tv_fdate"
android:layout_width="140dp"
android:layout_height="match_parent"
android:layout_toRightOf="@id/tv_pcode"
android:gravity="left"
android:textAppearance="?android:textAppearanceSmall"
android:text="feed datetime" />
<TextView
android:id="@+id/tv_qty"
android:layout_width="55dp"
android:layout_height="match_parent"
android:layout_toRightOf="@+id/tv_fdate"
android:layout_marginLeft="5dp"
android:gravity="right"
android:textAppearance="?android:textAppearanceSmall"
android:text="fqty" />
<TextView
android:id="@+id/tv_staff"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="@+id/@+id/tv_qty"
android:layout_marginLeft="10dp"
android:gravity="left"
android:textAppearance="?android:textAppearanceSmall"
android:text="staff name" />
</RelativeLayout>
The offending bit of Java, apparently I cannot have more than 2 TextViews and they must be TextViews. That's just as unacceptable as the SimpleAdaptor...
Code:
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private ListView listView;
private ProgressDialog progressdialog;
private String TAG = MainActivity.class.getSimpleName();
private String link, pgroup;
// instantiate a hashmap to hold json value-pair
ArrayList<HashMap<String, String>> mList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mList= new ArrayList<HashMap<String, String>>();
listView = (ListView) findViewById(R.id.mlist);
// ...various unrelated declarations...
}
protected void onPostExecute(Void result) {
super.onPostExecute(result);
// shutdown progress dialog
if (progressdialog.isShowing()) progressdialog.dismiss();
// stuff the parsed json from the arraylist into our listview
// ... lots of mundane code loading name-value pairs intoArray<HashMap<String,String>>
/*** works well but has unacceptable limitations in clearing and scrolling***
ListAdapter listadapter = new SimpleAdapter(
MainActivity.this,
mastbeckenList,
R.layout.mastbecken_list_layout,
new String[]{"pcode", "fdate", "qty", "staff"},
new int[] {R.id.tv_pcode, R.id.tv_fdate, R.id.tv_qty, R.id.tv_staff});
***/
ArrayAdapter<HashMap<String,String>> listAdapter = new ArrayAdapter<HashMap<String,String>> (
MainActivity.this,
R.layout.m_list_layout,
mList );
Log.e(TAG, "4. ArrayAdapter error" );
// clear the adapter
listView.setAdapter(null);
// ...then plug the listview into the adapter to display the new records
listView.setAdapter(listAdapter);
//
}
UPDATE12/7/17 4:17
Aww, gee, do I have to customize an ArrayAdaptor? Is there a less intensive way of doing it?
Last edited: