I am working on an Android v22 code. For some reason the List View simply doesn't show up and I have been trying but caot figure out why. There are no errors. Just a blank screen. I have tried debugging it and it goes smoothly upto the last line allianceActivityList.setAdapter(adapter); At that point, hitting F7 takes me inside the ListView.java file, in the code
public void setAdapter(ListAdapter adapter) {
if (mAdapter != null && mDataSetObserver != null) {
mAdapter.unregisterDataSetObserver(mDataSetObserver);
}
I did notice that 'mAdapter' and 'mDataSetObserver' were both highlighted in red. But I don't know if it's normal behaviour.
The code in Main activity that calls listview is below.
public class PlayerGrowthActivity extends AppCompatActivity {
public static final String LOGTAG = "LnK ActvPlayerGrowth: ";
private int readJSONActivityFile = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_player_growth);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
FileIO fileIO = new FileIO();
ActivityTrackerDataSource activityTrackerDataSource = new ActivityTrackerDataSource(PlayerGrowthActivity.this);
Integer allianceID = 3732;
//allianceID = -1; //dont reload the json files to sqlite table
if (readJSONActivityFile == 1){
try {
fileIO.ReadJSONFile(PlayerGrowthActivity.this, "activity_tracker1.json" );
} catch (IOException e) {
e.printStackTrace();
}
}
ArrayList<String[]> playerActivity = activityTrackerDataSource.getActivityPlayers(allianceID);
ListView allianceActivityList = (ListView) findViewById(R.id.listViewPlayerActivity);
ListAdapter adapter = new ActivityTableAdapter(PlayerGrowthActivity.this, playerActivity);
allianceActivityList.setAdapter(adapter);
activity_player_growth.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/MyTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/MyTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_player_growth" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />
content_player_growth.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="app.monty.lordsknightsapp.PlayerGrowthActivity"
tools:showIn="@layout/activity_player_growth">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:id="@+id/linearLayout">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="@+id/LinLayoutAllianceSelect">
<Spier
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/spinAllianceName"
android:spierMode="dropdown" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="223dp"
android:id="@+id/LinLayoutOptions">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/textView"
android:layout_gravity="end" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/textView2"
android:layout_gravity="end" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="212dp">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New RadioButton"
android:id="@+id/radioButton"
android:layout_gravity="end" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New CheckBox"
android:id="@+id/checkBox"
android:layout_marginStart="212dp" />
</LinearLayout>
</LinearLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listViewPlayerActivity">
</ListView>
</RelativeLayout>
It might be helpful to mention that this is a new screen/feature. The old screens/features show lists successfully. Also, this is the first time, I used Android's built in drag and drop to create the layout files. not sure if that is causing the unexpected behavior.
