Hey Leute ,
ich erzähl euch mal was ich gemacht habe sprich vorhabe .
Erstmal s habe ich CoverFlow mit meiner Datenbank Firebase verbunden und es so hinbekommen dass die Bilder angezeigt werden so weit so gut.
Danach wollte ich eigentlich dass wenn man auf ein CoverFlow Bild klickt es auf einer anderen Activity das Bild angezeigt wird plus noch eventuell Name von der Datenbank.
Habe unzählige Versuche mit Intent gestartet , leider ohne Erfolg
Das ist mein Fragment mit Coverflow :
Code
public class HomeFragment extends Fragment {
private static final String TAG = "HomeFragment";
//COVERFLOW
private FeatureCoverFlow coverFlow;
private FoodAdapter adapter;
private TextSwitcher mCaption;
private List<Food> rowItems = new ArrayList<>();
private FirebaseAuth mAuth;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_home, container, false);
//----------------------COVERFLOW-----------------------------
mAuth = FirebaseAuth.getInstance();
showFood();
mCaption =(TextSwitcher)view.findViewById(R.id.caption);
mCaption.setFactory(new ViewSwitcher.ViewFactory() {
@Override
public View makeView() {
LayoutInflater inflater = LayoutInflater.from(getContext());
TextView txt = (TextView)inflater.inflate(R.layout.layout_title,null);
return txt;
}
});
final Animation in = AnimationUtils.loadAnimation(getContext(), R.anim.slide_in_top);
Animation out = AnimationUtils.loadAnimation(getContext(), R.anim.slide_out_bottom);
mCaption.setAnimation(in);
mCaption.setAnimation(out);
adapter = new FoodAdapter(rowItems, getContext());
coverFlow = (FeatureCoverFlow)view.findViewById(R.id.coverFlow);
coverFlow.setAdapter(adapter);
coverFlow.setOnScrollPositionListener(new FeatureCoverFlow.OnScrollPositionListener() {
@Override
public void onScrolledToPosition(int position) {
mCaption.setText(rowItems.get(position).getCaption());
}
@Override
public void onScrolling() {
}
});
coverFlow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent = new Intent(getActivity(), FoodDetailActivity.class);
intent.putExtra("dataId",i);
startActivity(intent);
}
});
coverFlow.setOnScrollPositionListener(new FeatureCoverFlow.OnScrollPositionListener() {
@Override
public void onScrolledToPosition(int position) {
position++;
}
@Override
public void onScrolling() {
}
});
return view;
}
//-----------------------------FIREBASE--------------------------
public void showFood(){
final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
DatabaseReference DB = FirebaseDatabase.getInstance().getReference().child("photos");
DB.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
if (dataSnapshot.exists()){
Food item = new Food(dataSnapshot.getKey(), dataSnapshot.child("caption").getValue().toString(), dataSnapshot.child("image_path").getValue().toString());
rowItems.add(item);
adapter.notifyDataSetChanged();
}
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
Alles anzeigen
Und das ist die Activity die die Datei abfangen soll
Code
public class FoodDetailActivity extends AppCompatActivity {
ImageView food_image;
TextView food_title,food_tag;
Context context;
private Intent intent;
private List<Food> rowItems = new ArrayList<>();
private FoodAdapter adapter;
@Override
protected void onCreate( Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fooddetail);
//food_image = (KenBurnsView)findViewById(R.id.food_image);
food_image = (ImageView) findViewById(R.id.food_image);
food_title = (TextView) findViewById(R.id.food_title);
food_tag = (TextView) findViewById(R.id.food_tag);
if (getIntent() != null){
int food_index = getIntent().getIntExtra("dataId",-1);
if (food_index != -1)
load(food_index);
}
}
private void load(int index){
Food food = rowItems.get(index);
Picasso.with(getBaseContext()).load(food.getImage_path()).into(food_image);
}
}
Alles anzeigen
und das ist mein Adapter
Code
blic class FoodAdapter extends BaseAdapter{
List<Food> foodList;
Context context;
public FoodAdapter(List<Food> foodList, Context context) {
this.foodList = foodList;
this.context = context;
}
@Override
public int getCount() {
return foodList.size();
}
@Override
public Object getItem(int i) {
return foodList.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
View rootView = view;
if (rootView==null){
rootView = LayoutInflater.from(context).inflate(R.layout.layout_item, null);
TextView name = (TextView)rootView.findViewById(R.id.label);
ImageView image = (ImageView)rootView.findViewById(R.id.image);
name.setText(foodList.get(i).getCaption());
Picasso.with(context).load(foodList.get(i).getImage_path()).into(image);
}
return rootView;
}
}
Alles anzeigen
Jetzt habe ich euch alles geschickt. Bin echt sau am verzweifeln
Danke vorweg