Hallo zusammen, Ich hab eine onclickable ListView. ich möchte wenn ich ein Item davon anklicke eine neue Aktivität aufgeht.
Soweit hab ich schon selbst hinbekommen.
Nun In dieser ListView sind Images. Ich möchte, dass wenn ich ein Image anclicke dieses Bild dann als Hintergrund meiner neuen Aktivitä werden.
Eigentlich class ItemList ist interessant. Kann mir einer sagen wie ich den code unter
onItemClick ändern kann dass das Bild da hinzugefügt wird??
Java
package com.example.de.sasioutlet;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import java.util.ArrayList;
/**
* Created by user on 02.06.2017.
*/
public class Deals extends AppCompatActivity {
ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_deals);
listView = (ListView) findViewById(R.id.listView);
ArrayList<Card> list = new ArrayList<>();
list.add(new Card("drawable://" + R.drawable.img_1079, "Arizona Dessert", "1000"));
list.add(new Card("drawable://" + R.drawable.img_1080, "Bamf", "10054530"));
list.add(new Card("drawable://" + R.drawable.img_1081, "Colorado Mountains", "23425"));
list.add(new Card("drawable://" + R.drawable.img_1082, "Cork", "3345"));
CustomListAdapter adapter = new CustomListAdapter(this, R.layout.card_layout_main, list);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new ItemList(list));
BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_NavView_bar);
BottomNavigationViewHelper.disableShiftMode(bottomNavigationView);
Menu menu = bottomNavigationView.getMenu();
MenuItem menuItem = menu.getItem(1);
menuItem.setChecked(true);
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener(){
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()){
case R.id.action_home:
startActivity(new Intent(Deals.this, MainActivity.class));
break;
case R.id.action_flight:
startActivity(new Intent(Deals.this, Flight.class));
break;
case R.id.action_shopping:
startActivity(new Intent(Deals.this, ShoppingItem.class));
break;
case R.id.action_shopping_Cart:
startActivity(new Intent(Deals.this, ShoppingCart.class));
break;
case R.id.action_deals:
break;
}
return false;
}
});
}
class ItemList implements AdapterView.OnItemClickListener{
ArrayList<Card> list;
public ItemList(ArrayList<Card> list){
this.list = list;
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
/*Card item = list.get(position);
String imageURL = item.getImgURL();
ImageView image;
RelativeLayout relative;
image =(ImageView)findViewById(R.id.image);
relative=(RelativeLayout)findViewById(R.id.relative);
RelativeLayout.LayoutParams params=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
image.setLayoutParams(params);
relative.addView(image, params);*/
if(position == 0){
Intent intent= new Intent(view.getContext(), ItemActivity.class);
startActivityForResult(intent,0);
}
}
}
}
Alles anzeigen
Hier sollte das Bild angezeigt werden!
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/relative">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark"
android:id="@+id/image"/>
</RelativeLayout>
Alles anzeigen
Kan mir einer einen Tipp geben?
Danke