Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialaroshinemunasinghe
5,649 PointsAfter emu. it shows up "There is no data to display"
After I add ArrayAdapter..
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_daily_forecast);
String[] daysOfTheWeek = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
// Data days of the week.
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, daysOfTheWeek); // the key thing that all of them have in commin is they contain text views that can display the string data that we have.
setListAdapter(adapter);
}
I can see the list but also "There is no data to display" What have I done wrong?
aroshinemunasinghe
5,649 Points@Kourosh Raeen Yes!
aroshinemunasinghe
5,649 PointsSo I have copy pasted and got red warning @string I removed it and its working Thank you !!
Kourosh Raeen
23,733 PointsYou're welcome! Are you saying that you removed the line: android:text="@string/no_daily_forecast_data" ? Because without it the message "There is no data to display" will not get displayed when there is not data. You probably got the red warning because the following line is missing from the strings.xml file in the values folder:
<string name="no_daily_forecast_data">There is no data to display.</string>
If you add the above line that error should go away. Or you can just put the text directly in the TextView:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="There is no data to display"
android:id="@android:id/empty"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:textColor="#ffffffff"/>
However, the better practice is to add a string resource to string.xml as I explained above.
1 Answer
Kourosh Raeen
23,733 PointsIn the TextView in activity_daily_forecast.xml, are you using the special id: android:id="@android:id/empty" ? The code should look like this:
<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"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="teamtreehouse.com.stormy.ui.DailyForecastActivity"
android:background="@drawable/bg_gradient">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@android:id/list"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/no_daily_forecast_data"
android:id="@android:id/empty"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:textColor="#ffffffff"/>
</RelativeLayout>
Kourosh Raeen
23,733 PointsKourosh Raeen
23,733 PointsSo when you click on the 7 Day button you can see the days of the week listed but you also see the message "There is no data to display.", is that right?