この質問は既に多くの時間尋ねられていますが、私はすべての回答に行きました。フラグメント内のリストビューには何も表示されません
したがって、アプリケーションの問題は、ArrayAdapterを使用してListListにArrayListを設定しようとしていることです。アプリケーションのMainActivityは、起動時に白い画面以外の何も表示しません。
は、ここでは、ListViewコントロールアダプタを設定すると MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public static class PlaceholderFragment extends Fragment{
private ArrayAdapter<String> mForecastAdapter;
public PlaceholderFragment(){}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
//Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
String[] forecastArray = {
"Today - Sunny - 88/63",
"Tomorrow - Foggy - 70/46",
"Weds - Cloudy - 72/63",
"Thurs - Rainy - 64/51",
"Fri - Foggy - 70/46",
"Sat - Sunny - 76/68"
};
List<String> weekForecast = new ArrayList<String>(Arrays.asList(forecastArray));
ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast);
listView.setAdapter(mForecastAdapter);
mForecastAdapter = new ArrayAdapter<String>(
//The current context (current activity)
getActivity(),
//ID of list item layout
R.layout.list_item_forecast,
//id of the textView to populate
R.id.list_item_forecast_textview,
//data to populate
weekForecast
);
return rootView;
}
}
ここfragment_main.xml
<FrameLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.gautamhans.sunshine.app.MainActivityFragment"
tools:showIn="@layout/activity_main">
<ListView
android:id="@+id/listview_forecast"
android:layout_width="match_parent"
android:layout_height="667dp"
/>
</FrameLayout>
がlist_item_forecast.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:id="@+id/list_item_forecast_textview"
>
</TextView>
あなたのページャアダプタのコードを共有しています。 –
申し訳ありませんが、ページャアダプタはありません。 @ArpitRatan –