は私がsqliteのを使って自分のデータを入力したが、私は、私は混乱していた中で意図を使用してrecylerビュー内の小包を使用する場合どのように私は、アダプタの位置を得るのですか小包で、ここで はSqliteをデータベースにクリックRecylerビューに小包を送信するためにどのように
が私のコード..です
私のモデルクラスをバンドルに保存し、他の活動に意図を通してそれを送信し、他の活動にそれを収集する
public class FamousPeople implements Parcelable {
private static final String FAMOUS_NAME = "famous name";
private static final String FAMOUS_PHOTO="photo";
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
private long id;
private String name;
private String photo;
private String details;
public String getDetails() {
return details;
}
public void setDetails(String details) {
this.details = details;
}
public String getPhoto() {
return photo;
}
public void setPhoto(String photo) {
this.photo = photo;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(this.id);
dest.writeString(this.name);
dest.writeString(this.photo);
dest.writeString(this.details);
}
public FamousPeople() {
}
protected FamousPeople(Parcel in) {
this.id = in.readLong();
this.name = in.readString();
this.photo = in.readString();
this.details = in.readString();
}
public static final Parcelable.Creator<FamousPeople> CREATOR = new Parcelable.Creator<FamousPeople>() {
@Override
public FamousPeople createFromParcel(Parcel source) {
return new FamousPeople(source);
}
@Override
public FamousPeople[] newArray(int size) {
return new FamousPeople[size];
}
};
}
私は
public class BiographyFragment extends Fragment {
StaggeredGridLayoutManager staggeredGridLayoutManager;
List<FamousPeople> famousPeoples;
BiographyDataSource biographyDataSource;
public BiographyFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
biographyDataSource=new BiographyDataSource(getActivity());
biographyDataSource.open();
Log.v("data","database created");
View view=inflater.inflate(R.layout.fragment_biography, container, false);
RecyclerView recyclerView= (RecyclerView)view.findViewById(R.id.my_recycler_view);
recyclerView.setHasFixedSize(true);
staggeredGridLayoutManager=new
StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL);
recyclerView.setLayoutManager(staggeredGridLayoutManager);
List<FamousPeople> famousPeoples=biographyDataSource.findRecords();
List<FamousPeople> famousPeopleArrayList=biographyDataSource.findRecords();
if(famousPeoples.size()==0){
BioData bioData=new BioData();
bioData.createdata();
famousPeoples=biographyDataSource.findRecords();
}
RecyclerViewAdapter recyclerViewAdapter=
new RecyclerViewAdapter(getActivity(),famousPeoples);
recyclerView.setAdapter(recyclerViewAdapter);
return view;
}
}
**マイデータリストは、それを通して、私が収集していたデータ**私は
public class BioData
{
List<FamousPeople> famousPeoples;
BiographyDataSource biographyDataSource;
public List<FamousPeople> createdata(){
FamousPeople famousPeople=new FamousPeople();
famousPeople.setName("rahul");
famousPeople.setPhoto("amitabh");
famousPeople.setDetails("hello this is amitabh");
biographyDataSource.create(famousPeople);
Log.v("data", "inserted value 1");
famousPeople=new FamousPeople();
famousPeople.setName("cvraman");
famousPeople.setPhoto("cvraman");
famousPeople.setDetails("hello this is amitabh");
biographyDataSource.create(famousPeople);
Log.v("data", "inserted value 2");
famousPeople=new FamousPeople();
famousPeople.setName("indira");
famousPeople.setPhoto("indira");
famousPeople.setDetails("hello this is amitabh");
biographyDataSource.create(famousPeople);
Log.v("data", "inserted value 3");
famousPeople=new FamousPeople();
famousPeople.setName("modi");
famousPeople.setPhoto("modi");
famousPeople.setDetails("hello this is amitabh");
biographyDataSource.create(famousPeople);
Log.v("data", "inserted value 4");
return famousPeoples;
}
}
マイrecylerビューSQLiteデータベースを使用しています
マイフラグメントクリック時の位置を収集し、適切なデータを他のアクティビティに送信するパーセルを使用するのが混乱している
class BiographyViewHolder extends RecyclerView.ViewHolder
implements View.OnClickListener {
public TextView textView;
public ImageView imageView;
BiographyDataSource biographyDataSource;
List<FamousPeople> famousPeoples;
public BiographyViewHolder(View itemView)
{
super(itemView);
itemView.setOnClickListener(this);
textView= (TextView) itemView.findViewById(R.id.country_name);
imageView= (ImageView) itemView.findViewById(R.id.country_photo);
}
@Override
public void onClick(View view) {
List<FamousPeople> famousPeopleArrayList=biographyDataSource.findRecords();
if(famousPeoples.size()==0){
BioData bioData=new BioData();
bioData.createdata();
famousPeoples=biographyDataSource.findRecords();
}
Bundle bundle=new Bundle();
// bundle.putParcelable("test",famousPeopleArrayList.get(getAdapterPosition()));
Intent intent=new Intent(view.getContext(),DetailActivity.class);
intent.putExtras(bundle);
view.getContext().startActivity(intent);
}
}