我正在学习udacity课程,我对Android很新,所以我知道我缺少一些非常基本的东西。
我有两个符号变量给我错误,说他们无法解析R.layout.list_item_forecast和R.id.list_item_forecast_textview
感谢任何帮助。
package com.example.android.sunshine.app;
import android.support.v7.app.ActionBarActivity;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.ArrayAdapter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
ArrayAdapter<String> mForecastAdapter;
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
String[] data = {
"Today - Sunny - 88/63",
"Tomorrow - Foggy 70/40",
"Weds - Cloudy 72/62",
"Thurs - Snow 34 Possible!!",
"Fri - Milk Bread TP",
"Sat - Cloudy 72/62",
"Sun - Cloudy 72/62",
};
List<String> weekForecast = new ArrayList<String>(Arrays.asList(data));
char shape;
mForecastAdapter = new ArrayAdapter<String>(
getActivity(), // The current context (this activity)
R.layout.list_item_forecast, // The name of the layout ID.
R.id.list_item_forecast_textview, // The ID of the textview to populate.
weekForecast);
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast);
listView.setAdapter(mForecastAdapter);
return rootView;
}
}
}
答案 0 :(得分:0)
layout.list_item_forecast是定义文本视图的每一行的布局文件,它只包含文本视图。
R.id.list_item_forecast_textview
是布局文件R.layout.list_item_forecast
中包含的文本视图的ID。
分享您的布局文件以获得进一步的帮助:)