私は Android アプリに取り組んでおり、フラグメントを機能させようとしていますが、問題が発生しました。
アプリが起動すると、2 つのフラグメントを格納するアクティビティが読み込まれます。Fragment1 には保存されたログインのリストが含まれ、Fragment 2 にはそのログインに関連付けられた詳細が表示されます。
リスト フラグメントは、SQLite データベースからデータを取得して画面に表示することになっています。項目をクリックすると、2 番目のフラグメントが読み込まれますが、最初の段階が機能しません。
私の主な活動クラスには、次のものがあります。
public class PasswordListMain extends Activity {
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.password_management);
}
}
password_management XML ファイルには、次のものが含まれています。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
android:id="@+id/passwordList"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.BoardiesITSolutions.PasswordManager.PasswordListFrag">
</fragment>
</LinearLayout>
これはポートレート画面であるため、フラグメントが含まれているだけです。並べて機能させる前に、このビットを機能させると思いました。
PasswordListFrag には以下が含まれます。
public class PasswordListFrag extends ListFragment{
Common common;
com.BoardiesITSolutions.logic.ManagePasswordList managePasswordList;
ArrayList<String> savedPassword;
TextView txtNoRecords;
ListView myListView;
ArrayAdapter<Spanned> passwordArrayAdapter;
AdView adView;
@Override
public View onCreateView(LayoutInflater inflator, ViewGroup container, Bundle savedInstanceState)
{
View view = inflator.inflate(R.layout.password_list, container, false);
myListView = getListView();
common = new Common(getActivity().getApplicationContext());
//AdView adView = (AdView)findViewById(R.id.adView);
common.requestAdvert(adView);
managePasswordList = new ManagePasswordList(getActivity().getApplicationContext());
//txtNoRecords = (TextView)findViewById(R.id.password_noRecords);
populateListArray();
common.showToastMessage("Adapter updated", Toast.LENGTH_LONG);
//myListView.setOnItemClickListener(mListView);
return view;
}
private void populateListArray()
{
ArrayList<Spanned> passwords = managePasswordList.getPasswordList();
if (passwords != null && passwords.size() > 0)
{
passwordArrayAdapter = new ArrayAdapter<Spanned>(getActivity().getApplicationContext(),
android.R.layout.simple_list_item_1, passwords);
setListAdapter(passwordArrayAdapter);
passwordArrayAdapter.setNotifyOnChange(true);
myListView.setTextFilterEnabled(true);
txtNoRecords.setVisibility(View.GONE);
}
else
{
txtNoRecords.setVisibility(View.VISIBLE);
}
}
}
以下は、リスト フラグメントの XML です。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView android:id="@+id/password_noRecords"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:text="There are currently\nno saved logins"
android:textSize="20dp"
android:textStyle="bold|italic"/>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/adView">
</ListView>
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="5555555"
ads:adSize="BANNER"
android:layout_alignParentBottom="true">
</com.google.ads.AdView>
</RelativeLayout>
アプリが読み込まれると、この画面を読み込もうとすると即座にクラッシュします。
エラーは
java.lang.RuntimeException: Unable to start activity ComponentInfo
PasswordListMain: android.view.InflatException: Binary XML file line
#7 Error inflating class fragment
何が原因なのか、問題を解決する方法がわかりません。
ご協力いただきありがとうございます。