What do you see in with logcat? On Sun, May 22, 2011 at 11:40 AM, giels <[email protected]> wrote: > I have som problem with this code, > my application failed since i start it. > > I notice that my setListAdapater is a main problem. > Helps me please : > > my code : > > public class main extends Activity { > /** Called when the activity is first created. */ > > boolean onOff=true;//Bonton onOff de la lampe > > // I use HashMap arraList which takes objects > private ArrayList <HashMap<Object, Object>> myList; > private static final String IMAGE = "atImag"; > private static final String NAME = "nom"; > private static final String ATTRIBUT1 = "attribut1"; > private static final String ATTRIBUT2 = "attribut2"; > private static final String ATTRIBUT3 = "attribut3"; > private static final String PLUS = "plus"; > private static final String MOINS = "moins"; > private static final String ON = "on"; > > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > menu(); > } > > public void menu() // fonction du menu > { > ListView listView = (ListView)findViewById(R.id.listlist); > myList = new ArrayList<HashMap<Object,Object>>(); > HashMap<Object, Object> listAtt; > > //With the help of HashMap add Key, Values of Book, like > name,price and icon path > listAtt = new HashMap<Object, Object>(); > listAtt.put(IMAGE,R.drawable.lamp); > listAtt.put(NAME, "lampe 1"); > listAtt.put(ATTRIBUT1, "100 kW/h"); > listAtt.put(ATTRIBUT2, "24 °C"); > listAtt.put(ATTRIBUT3, "25%"); > myList.add(listAtt); > > listAtt = new HashMap<Object, Object>(); > listAtt.put(IMAGE,R.drawable.lamp0); > listAtt.put(NAME, "lampe 2"); > listAtt.put(ATTRIBUT1, "300 kW/h"); > listAtt.put(ATTRIBUT2, "30°C"); > listAtt.put(ATTRIBUT3, "75%"); > myList.add(listAtt); > > listView.setAdapter(new myListAdapter(myList,this)); > listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); > > } > > private class myListAdapter extends BaseAdapter{ > > > class ViewHolder { > ImageView atImag; > TextView nom; > TextView attribut1; > TextView attribut2; > TextView attribut3; > ImageButton plus; > ImageButton moins; > ToggleButton on; > } > > private ArrayList<HashMap<Object, Object>> Liste; > private LayoutInflater mInflater; > > public myListAdapter(ArrayList<HashMap<Object, Object>> > list, Context context) > { > Liste= list; > mInflater = LayoutInflater.from(context); > } > > public int getCount() > { > // TODO Auto-generated method stub > return Liste.size(); > } > > @Override > public Object getItem(int position) { > // TODO Auto-generated method stub > return Liste.get(position); > } > @Override > public long getItemId(int position) { > // TODO Auto-generated method stub > return position; > } > @Override > public View getView(int position, View convertView, > ViewGroup parent) > { > // TODO Auto-generated method stub > // A ViewHolder keeps references to children views to > avoid unneccessary calls > // to findViewById() on each row. > ViewHolder holder; > // When convertView is not null, we can reuse it > directly, there is no need > // to reinflate it. We only inflate a new View when > the convertView supplied > // by ListView is null > if (convertView == null) > { > convertView = > mInflater.inflate(R.layout.listview1, null); > // Creates a ViewHolder and store references to > the two children views > // we want to bind data to. > holder = new ViewHolder(); > > holder.atImag=(ImageView)convertView.findViewById(R.id.image); > holder.nom = > (TextView)convertView.findViewById(R.id.txt1); > holder.attribut1= > (TextView)convertView.findViewById(R.id.txt2); > holder.attribut2= > (TextView)convertView.findViewById(R.id.txt3); > holder.attribut3= > (TextView)convertView.findViewById(R.id.txt4); > holder.plus = (ImageButton) > convertView.findViewById(R.id.but1); > holder.moins = > (ImageButton)convertView.findViewById(R.id.but2); > holder.on = > (ToggleButton)convertView.findViewById(R.id.but3); > convertView.setTag(holder); > } > else > { > // Get the ViewHolder back to get fast access to > the TextView > // and the ImageView. > holder = (ViewHolder) convertView.getTag(); > } > // Bind the data with the holder. > > > holder.atImag.setImageDrawable((Drawable)Liste.get(position).get(IMAGE)); > holder.nom.setText((String) > Liste.get(position).get(NAME)); > holder.attribut1.setText((String) > Liste.get(position).get(ATTRIBUT1)); > holder.attribut2.setText((String) > Liste.get(position).get(ATTRIBUT2)); > holder.attribut3.setText((String) > Liste.get(position).get(ATTRIBUT3)); > holder.plus.setClickable(true); > holder.moins.setClickable(true); > holder.on.setClickable(true); > return convertView; > } > > > } > > > private OnClickListener tst1=new OnClickListener()// fonction de > test de changement de lumière > { > > public void onClick(View v) > { > ImageButton test1=(ImageButton)findViewById(R.id.bouton6); > > if(onOff) > { > > test1.setImageDrawable(getResources().getDrawable(R.drawable.lamp));// > on set l'image > onOff=false;//on met le bouton en false > menu();//on retourne a notre fonction > } > else > { > > test1.setImageDrawable(getResources().getDrawable(R.drawable.lamp0));// > on set l'image > onOff=true;//on met le bouton en true > menu();//on retourne a notre fonction > } > > } > }; > } > > > my xml files "main": > > > <?xml version="1.0" encoding="utf-8"?> > <LinearLayout > xmlns:android="http://schemas.android.com/apk/res/android" > android:layout_width="fill_parent" > android:layout_height="fill_parent" > android:background="@drawable/fond7" > android:orientation="vertical"> > > <RelativeLayout > android:layout_width="fill_parent" > android:layout_height="fill_parent" > android:layout_weight="8" > android:background="@drawable/tst"> > <TextView > android:layout_width="fill_parent" > android:layout_height="wrap_content" > android:text="@string/app_name" > android:textColor="#ffffffff" > android:textStyle="normal" > android:textSize="25dip" > android:gravity="center" > android:layout_centerInParent="true"> > </TextView> > <View > android:layout_width="fill_parent" > android:layout_height="1dip" > android:layout_marginLeft="5dip" > android:layout_marginRight="5dip" > android:background="#ffffffff" > android:layout_alignParentBottom="true"> > </View> > </RelativeLayout> > <LinearLayout > android:layout_width="fill_parent" > android:layout_height="fill_parent" > android:layout_weight="3" > android:orientation="horizontal"> > <ListView > android:layout_width="fill_parent" > android:layout_height="fill_parent" > android:layout_weight="4" > android:layout_margin="5dip" > android:entries="@array/init" > android:cacheColorHint="@android:color/transparent"> > </ListView> > <ListView > android:id="@+id/listlist" > android:layout_width="fill_parent" > android:layout_height="fill_parent" > android:layout_weight="1" > android:layout_margin="5dip" > android:cacheColorHint="@android:color/transparent"> > </ListView> > > </LinearLayout> > <RelativeLayout > android:orientation="vertical" > android:layout_width="fill_parent" > android:layout_height="fill_parent" > android:layout_weight="8" > android:background="@drawable/tst"> > <View > android:layout_width="fill_parent" > android:layout_height="1dip" > android:layout_marginLeft="5dip" > android:layout_marginRight="5dip" > android:background="#ffffffff" > android:layout_alignParentTop="true"> > </View> > <ImageButton > android:id="@+id/bouton1" > android:layout_width="60dip" > android:layout_height="60dip" > android:layout_marginLeft="5dip" > android:layout_marginRight="5dip" > android:layout_centerInParent="true" > android:scaleType="fitXY" > android:src="@drawable/lock"> > </ImageButton> > <ImageButton > android:id="@+id/bouton2" > android:layout_width="60dip" > android:layout_height="60dip" > android:layout_marginLeft="5dip" > android:layout_marginRight="5dip" > android:layout_centerVertical="true" > android:layout_toRightOf="@id/bouton1" > android:scaleType="fitXY" > android:src="@drawable/electromenager"> > </ImageButton> > <ImageButton > android:id="@+id/bouton3" > android:layout_width="60dip" > android:layout_height="60dip" > android:layout_marginLeft="5dip" > android:layout_marginRight="5dip" > android:layout_centerVertical="true" > android:layout_toRightOf="@id/bouton2" > android:scaleType="fitXY" > android:src="@drawable/media"> > </ImageButton> > <ImageButton > android:id="@+id/bouton4" > android:layout_width="60dip" > android:layout_height="60dip" > android:layout_marginLeft="5dip" > android:layout_marginRight="5dip" > android:layout_centerVertical="true" > android:layout_toRightOf="@id/bouton3" > android:scaleType="fitXY" > android:src="@drawable/option"> > </ImageButton> > <ImageButton > android:id="@+id/bouton5" > android:layout_width="60dip" > android:layout_height="60dip" > android:layout_marginLeft="5dip" > android:layout_marginRight="5dip" > android:layout_centerVertical="true" > android:layout_toLeftOf="@id/bouton1" > android:scaleType="fitXY" > android:src="@drawable/temp"> > </ImageButton> > <ImageButton > android:id="@+id/bouton6" > android:layout_height="60dip" > android:layout_marginLeft="5dip" > android:layout_marginRight="5dip" > android:layout_centerVertical="true" > android:layout_toLeftOf="@id/bouton5" > android:scaleType="fitXY" > android:src="@drawable/lamp0" > android:layout_width="60dip"> > </ImageButton> > <ImageButton > android:id="@+id/bouton7" > android:layout_width="60dip" > android:layout_height="60dip" > android:layout_marginLeft="5dip" > android:layout_marginRight="5dip" > android:layout_centerVertical="true" > android:layout_toLeftOf="@id/bouton6" > android:scaleType="fitXY" > android:src="@drawable/bot2"> > </ImageButton> > > </RelativeLayout> > > </LinearLayout> > > my xml files "listview1" : > > > <?xml version="1.0" encoding="utf-8"?> > <LinearLayout > xmlns:android="http://schemas.android.com/apk/res/android" > android:layout_width="fill_parent" > android:layout_height="fill_parent" > android:background="@drawable/fond7" > android:orientation="vertical"> > > <RelativeLayout > android:layout_width="fill_parent" > android:layout_height="fill_parent" > android:layout_weight="8" > android:background="@drawable/tst"> > <TextView > android:layout_width="fill_parent" > android:layout_height="wrap_content" > android:text="@string/app_name" > android:textColor="#ffffffff" > android:textStyle="normal" > android:textSize="25dip" > android:gravity="center" > android:layout_centerInParent="true"> > </TextView> > <View > android:layout_width="fill_parent" > android:layout_height="1dip" > android:layout_marginLeft="5dip" > android:layout_marginRight="5dip" > android:background="#ffffffff" > android:layout_alignParentBottom="true"> > </View> > </RelativeLayout> > <LinearLayout > android:layout_width="fill_parent" > android:layout_height="fill_parent" > android:layout_weight="3" > android:orientation="horizontal"> > <ListView > android:layout_width="fill_parent" > android:layout_height="fill_parent" > android:layout_weight="4" > android:layout_margin="5dip" > android:entries="@array/init" > android:cacheColorHint="@android:color/transparent"> > </ListView> > <ListView > android:id="@+id/listlist" > android:layout_width="fill_parent" > android:layout_height="fill_parent" > android:layout_weight="1" > android:layout_margin="5dip" > android:cacheColorHint="@android:color/transparent"> > </ListView> > > </LinearLayout> > <RelativeLayout > android:orientation="vertical" > android:layout_width="fill_parent" > android:layout_height="fill_parent" > android:layout_weight="8" > android:background="@drawable/tst"> > <View > android:layout_width="fill_parent" > android:layout_height="1dip" > android:layout_marginLeft="5dip" > android:layout_marginRight="5dip" > android:background="#ffffffff" > android:layout_alignParentTop="true"> > </View> > <ImageButton > android:id="@+id/bouton1" > android:layout_width="60dip" > android:layout_height="60dip" > android:layout_marginLeft="5dip" > android:layout_marginRight="5dip" > android:layout_centerInParent="true" > android:scaleType="fitXY" > android:src="@drawable/lock"> > </ImageButton> > <ImageButton > android:id="@+id/bouton2" > android:layout_width="60dip" > android:layout_height="60dip" > android:layout_marginLeft="5dip" > android:layout_marginRight="5dip" > android:layout_centerVertical="true" > android:layout_toRightOf="@id/bouton1" > android:scaleType="fitXY" > android:src="@drawable/electromenager"> > </ImageButton> > <ImageButton > android:id="@+id/bouton3" > android:layout_width="60dip" > android:layout_height="60dip" > android:layout_marginLeft="5dip" > android:layout_marginRight="5dip" > android:layout_centerVertical="true" > android:layout_toRightOf="@id/bouton2" > android:scaleType="fitXY" > android:src="@drawable/media"> > </ImageButton> > <ImageButton > android:id="@+id/bouton4" > android:layout_width="60dip" > android:layout_height="60dip" > android:layout_marginLeft="5dip" > android:layout_marginRight="5dip" > android:layout_centerVertical="true" > android:layout_toRightOf="@id/bouton3" > android:scaleType="fitXY" > android:src="@drawable/option"> > </ImageButton> > <ImageButton > android:id="@+id/bouton5" > android:layout_width="60dip" > android:layout_height="60dip" > android:layout_marginLeft="5dip" > android:layout_marginRight="5dip" > android:layout_centerVertical="true" > android:layout_toLeftOf="@id/bouton1" > android:scaleType="fitXY" > android:src="@drawable/temp"> > </ImageButton> > <ImageButton > android:id="@+id/bouton6" > android:layout_height="60dip" > android:layout_marginLeft="5dip" > android:layout_marginRight="5dip" > android:layout_centerVertical="true" > android:layout_toLeftOf="@id/bouton5" > android:scaleType="fitXY" > android:src="@drawable/lamp0" > android:layout_width="60dip"> > </ImageButton> > <ImageButton > android:id="@+id/bouton7" > android:layout_width="60dip" > android:layout_height="60dip" > android:layout_marginLeft="5dip" > android:layout_marginRight="5dip" > android:layout_centerVertical="true" > android:layout_toLeftOf="@id/bouton6" > android:scaleType="fitXY" > android:src="@drawable/bot2"> > </ImageButton> > > </RelativeLayout> > > </LinearLayout> > > > my class "Attribut": > > package com.application.domotic; > > import java.util.Set; > > import android.graphics.drawable.Drawable; > import android.view.View; > import android.view.View.OnClickListener; > import android.widget.ImageButton; > import android.widget.ImageView; > import android.widget.TextView; > import android.widget.ToggleButton; > > /* > * Contient les informations à propos d'une lampe etc... > */ > > public class Attribut { > > ImageView atImag; > TextView nom; > TextView attribut1; > TextView attribut2; > TextView attribut3; > ImageButton plus; > ImageButton moins; > ToggleButton on; > > public Attribut() { > // TODO Auto-generated constructor stub > > } > > public Attribut(Drawable image, String nom, String att2, String att3, > String att4) { > // TODO Auto-generated constructor stub > atImag.setImageDrawable(image); > this.nom.setText(nom); > attribut1.setText(att2); > attribut2.setText(att3); > attribut3.setText(att4); > } > > public ImageView getAtImag() { > return atImag; > } > > public void setAtImag(Drawable drawable) { > this.atImag.setImageDrawable(drawable); > } > > public String getNom() { > return (String) nom.getText(); > } > > public void setNom(String nom) { > this.nom.setText(nom); > } > > public String getAttribut1() { > return (String) attribut1.getText(); > } > > public void setAttribut1(String attribut1) { > this.attribut1.setText(attribut1); > } > > public String getAttribut2() { > return (String) attribut2.getText(); > } > > public void setAttribut2(String attribut2) { > this.attribut1.setText(attribut2); > } > > public String getAttribut3() { > return (String) attribut3.getText(); > } > > public void setAttribut3(String attribut3) { > this.attribut1.setText(attribut3); > } > > public ImageButton getPlus() { > return plus; > } > > public void setPlus(ImageButton plus) { > this.plus = plus; > } > > public ImageButton getMoins() { > return moins; > } > > public void setMoins(ImageButton mois) { > this.moins = moins; > } > > public ToggleButton getOn() { > return on; > } > > public void setOn(ToggleButton on) { > this.on = on; > } > > } > > Thanks you > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en
-- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

