Reputation: 117
I'm having an issue to where none of my TextViews are showing up in the ListView. I'm not sure whether it is an issue with the layout or the java class itself. There are two images here, one of the application running after data had been entered into the database and one of what it is supposed to look like.
Layout for each row of data in ListView
Fragment for the ListView (Delete Button appears but not the TextViews)
row_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="123dp"
android:layout_height="wrap_content"
android:id="@+id/resultTeamNumber"
android:text="Here Number"
android:textSize="18dp"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/textPortcullis"
android:text="Portcullis:"
android:layout_above="@+id/textChevalFrise"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/resultPortcullis"
android:text="Yes/No"
android:singleLine="false"
android:layout_below="@+id/resultTeamNumber"
android:layout_marginLeft="110dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textChevalFrise"
android:text="Cheval de Frise:"
android:layout_below="@+id/resultPortcullis"
android:layout_alignParentStart="true"
android:singleLine="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/resultChevalFrise"
android:text="Yes/No"
android:singleLine="false"
android:layout_below="@+id/resultPortcullis"
android:layout_alignStart="@+id/resultPortcullis" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textMoat"
android:singleLine="false"
android:layout_below="@+id/textChevalFrise"
android:layout_alignParentStart="true"
android:text="Moat:" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/resultMoat"
android:text="Yes/No"
android:singleLine="false"
android:layout_below="@+id/resultChevalFrise"
android:layout_alignStart="@+id/resultChevalFrise" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textRamparts"
android:text="Ramparts:"
android:singleLine="false"
android:layout_below="@+id/textMoat"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/resultRamparts"
android:text="Yes/No"
android:singleLine="false"
android:layout_above="@+id/textDrawbridge"
android:layout_alignStart="@+id/resultMoat" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textDrawbridge"
android:text="Drawbridge:"
android:singleLine="false"
android:layout_below="@+id/textRamparts"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/resultDrawbridge"
android:text="Yes/No"
android:singleLine="false"
android:layout_below="@+id/resultRamparts"
android:layout_alignStart="@+id/resultRamparts" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textSallyPort"
android:text="Sally Port:"
android:singleLine="false"
android:layout_below="@+id/textDrawbridge"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/resultSallyPort"
android:singleLine="false"
android:layout_below="@+id/resultDrawbridge"
android:layout_alignStart="@+id/resultDrawbridge"
android:text="Yes/No" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textRockWall"
android:text="Rock Wall:"
android:singleLine="false"
android:layout_alignTop="@+id/resultPortcullis"
android:layout_toEndOf="@+id/resultPortcullis"
android:layout_marginStart="34dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/resultRockWall"
android:singleLine="false"
android:text="Yes/No"
android:layout_marginStart="46dp"
android:layout_above="@+id/resultRockTerrain"
android:layout_toEndOf="@+id/textRockTerrain" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textRockTerrain"
android:text="Rock Terrain:"
android:singleLine="false"
android:layout_below="@+id/textRockWall"
android:layout_alignStart="@+id/textRockWall" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/resultRockTerrain"
android:singleLine="false"
android:text="Yes/No"
android:layout_alignBottom="@+id/textRockTerrain"
android:layout_alignStart="@+id/resultRockWall" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textLowBar"
android:text="Low Bar:"
android:singleLine="false"
android:layout_above="@+id/resultRamparts"
android:layout_alignStart="@+id/textRockTerrain" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/resultLowBar"
android:singleLine="false"
android:text="Yes/No"
android:layout_below="@+id/resultRockTerrain"
android:layout_alignStart="@+id/resultRockTerrain" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#fff"
android:background="@color/colorPrimary"
android:text="Delete"
android:id="@+id/buttonDelete"
android:layout_below="@+id/textLowBar"
android:layout_toEndOf="@+id/textLowBar"
android:layout_above="@+id/resultSallyPort" />
</RelativeLayout>
ScoutFragment.java
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
/**
* A simple {@link Fragment} subclass.
*/
public class ScoutFragment extends Fragment {
FloatingActionButton addDataScout;
ListView eListScoutInfo;
SQLiteDatabase sqLiteDatabase;
DatabaseHelper databaseHelper;
Cursor cursor;
ListScoutInfoAdapter listScoutInfoAdapter;
public ScoutFragment() {
// Required empty public constructor
} //End of ScoutFragment
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_scout, null, false);
view.setBackgroundColor(Color.WHITE);
eListScoutInfo = (ListView) view.findViewById(R.id.listScoutInfo);
listScoutInfoAdapter = new ListScoutInfoAdapter(getActivity().getApplicationContext(), R.layout.row_layout);
eListScoutInfo.setAdapter(listScoutInfoAdapter);
databaseHelper = new DatabaseHelper(getActivity().getApplicationContext());
sqLiteDatabase = databaseHelper.getReadableDatabase();
cursor = databaseHelper.getInformation(sqLiteDatabase);
//Checks if information is available in cursor
if(cursor.moveToFirst()){
do {
//Declare all strings
String teamNumber, portcullis, chevalFrise, moat, ramparts, drawbridge, sallyPort, rockWall, rockTerrain, lowBar;
//Get strings from cursor
teamNumber = cursor.getString(cursor.getColumnIndex(DatabaseContract.NewDataInfo.COL_NUMBER));
portcullis = cursor.getString(cursor.getColumnIndex(DatabaseContract.NewDataInfo.COL_PORTCULLIS));
chevalFrise = cursor.getString(cursor.getColumnIndex(DatabaseContract.NewDataInfo.COL_CHEVAL_FRISE));
moat = cursor.getString(cursor.getColumnIndex(DatabaseContract.NewDataInfo.COL_MOAT));
ramparts = cursor.getString(cursor.getColumnIndex(DatabaseContract.NewDataInfo.COL_RAMPARTS));
drawbridge = cursor.getString(cursor.getColumnIndex(DatabaseContract.NewDataInfo.COL_DRAWBRIDGE));
sallyPort = cursor.getString(cursor.getColumnIndex(DatabaseContract.NewDataInfo.COL_SALLY_PORT));
rockWall = cursor.getString(cursor.getColumnIndex(DatabaseContract.NewDataInfo.COL_ROCK_WALL));
rockTerrain = cursor.getString(cursor.getColumnIndex(DatabaseContract.NewDataInfo.COL_ROCK_TERRAIN));
lowBar = cursor.getString(cursor.getColumnIndex(DatabaseContract.NewDataInfo.COL_LOW_BAR));
//Get methods from DatabaseProvider
DatabaseProvider databaseProvider = new DatabaseProvider(teamNumber, portcullis, chevalFrise, moat, ramparts,
drawbridge, sallyPort, rockWall, rockTerrain, lowBar);
//Pass objects to add method
listScoutInfoAdapter.add(databaseProvider);
listScoutInfoAdapter.notifyDataSetChanged();
} while (cursor.moveToNext());
} //End of if statement
//Setups Floating Action Button
addDataScout = (FloatingActionButton) view.findViewById(R.id.fab);
addDataScout.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
AddScoutDataFragment fragment = new AddScoutDataFragment();
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right);
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.commit();
} //End of onClick
}); //End of setOnClickListener
return view;
} //End of onCreateView
} //End of class
I don't believe the issue is with database showing the data because some of the TextViews in the ListView don't even use the data from inside the database.
Upvotes: 1
Views: 335
Reputation: 563
your row_layout.xml file textview in set textcolor:
<TextView
android:layout_width="123dp"
android:layout_height="wrap_content"
android:id="@+id/resultTeamNumber"
android:text="Here Number"
android:textSize="18dp"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:textColor="@android:color/black"
/>
Upvotes: 1
Reputation: 12379
It is theme issue on your end,probably textcolor set to white in your theme change these
<item name="android:textColorPrimary">@color/white</item>
<item name="android:textColorSecondary">@color/white</item>
change it to black
Upvotes: 1