Bookinfo.title、Bookinfo.author、Book.isbn変数のフラグメント内でこのエラーが発生します。理由はわかりません。すべてのドキュメントは、それを修正しようとすると別のエラーを表示します。Bookinfに関しては、ゲッターとセッターで構成される別のクラスがあります。BookDetailsFragmentクラスのFragmentという単語でエラーが発生します。エラーは、BookDetailsFragmentに@SuppressLint'NewApi'を追加することを示しています。どんな助けでも大歓迎です。
BookDetailsFragmentのコードは次のとおりです。
import android.app.Fragment;
public class BookDetailsFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//View view = inflater.inflate(R.layout.book_details, container, false);
View view = inflater.inflate(R.layout.book_details, null);
System.out.println("BookDetailsActivity executed");
//Defines the TextViews in R.layout.book_details
TextView bkTitle = (TextView)view.findViewById(R.id.bookTitle);
TextView bkAuth = (TextView)view.findViewById(R.id.bookAuthor);
TextView bkIsbn = (TextView)view.findViewById(R.id.bookISBN);
//Retrieve the bundle object passed from BuyFragTab
Bundle b = getArguments();
//Getting the item's clicked position and setting corresponding details
bkTitle.setText("Title: " + Bookinfo.title[b.getInt("position")]);
bkAuth.setText("Author: " + Bookinfo.author[b.getInt("position")]);
bkIsbn.setText("ISBN: " + Bookinfo.isbn[b.getInt("position")]);
return view;
}
}
Bookinfoクラスコードは次のとおりです。
package com.skipster.BookBarter;
public class Bookinfo {
private String title;
private String author;
private String isbn;
public Bookinfo(String title, String author, String isbn) {
this.title = title;
this.author = author;
this.isbn = isbn;
// TODO Auto-generated constructor stub
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getIsbn() {
return isbn;
}
public void setIsbn(String isbn) {
this.isbn = isbn;
}
//returns all the previous variables to the program that made the call
@Override
public String toString() {
return title + " " + author + " " + isbn;
}
}
BookDetailsActivityのコードは次のとおりです。
import android.os.Bundle;
import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
public class BookDetailsActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setting the layout for this activity
setContentView(R.layout.book_details_activity_layout);
//get fragment manager for fragment related operations
FragmentManager fm = getFragmentManager();
//get fragment transaction object, which can add, move or replace a fragmnt
FragmentTransaction ft = fm.beginTransaction();
//instantiating the fragment BookDetailsFragment
BookDetailsFragment detailsFragment = new BookDetailsFragment();
//creating a bundle object to pass the data (clicked item's position)
//from this activity to fragment
Bundle b = new Bundle();
//setting the data to the bundle object from the Intent
b.putInt("position", getIntent().getIntExtra("position", 0));
System.out.println("the bundle passed" + b);
//setting the bundle object to the fragment
detailsFragment.setArguments(b);
//adding the fragment to the fragment transaction
ft.add(R.id.book_details_fragment_container, detailsFragment);
//add the fragment transaction to backstack
ft.addToBackStack(null);
//Executing the transaction
ft.commit();
}
}
インテントを開始するonClickListenerのコードは次のとおりです。
bookLV.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position,
long id){
String selectTitle, selectAuthor, selectIsbn = null;
//When item is clicked, show it's detailed view
Bookinfo bkRecs = (Bookinfo)parent.getItemAtPosition(position);
//Creating an intent object to start BookDetailsActivity
Intent bkIntent = new Intent("com.skipster.BookBarter.BOOKDETAILSACTIVITY");
//Setting data (the clicked item's position to the intent
bkIntent.putExtra("position", position);
System.out.println("Data loaded for intent");
//Start the activity
startActivity(bkIntent);
System.out.println("Intent activity started");
}
});