for the billionth time i'm useing a CUSTOM LISTVIEW it inflates the
xml and getview gets called as many times as there is items in the
array...if you put a button in the xml no matter what way you format
the XML the button gets displayed multiple times not 1 time multiple
times .....no matter how you display the XML ....here is the code
modify it and give it a try and if your way works then i'll eat dirt.
package com.cuslistview;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
public class customlistview extends Activity implements
OnClickListener{
ListView l1;
private static class EfficientAdapter extends BaseAdapter {
private LayoutInflater mInflater;
private ArrayList<ArrayList<String>> ret=null;
public EfficientAdapter(Context context) {
Sax sax1 = new Sax();
try {
ret = sax1.SaxIni();
} catch (Exception e) {
e.printStackTrace();
}
mInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return ret.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertview, ViewGroup
parent) {
ViewHolder holder;
if (convertview == null) {
convertview = mInflater.inflate(R.layout.main,
parent,false);
holder = new ViewHolder();
//holder.text = (TextView)
convertview.findViewById(R.id.TextView01);
holder.text0 = (TextView)
convertview.findViewById(R.id.TextView0);
holder.text1 = (TextView)
convertview.findViewById(R.id.TextView1);
holder.text2 = (TextView)
convertview.findViewById(R.id.TextView2);
convertview.setTag(holder);
} else {
holder = (ViewHolder) convertview.getTag();
}
//holder.text.setText(ret.get(position) );
holder.text0.setText(ret.get(0).get(position));
holder.text1.setText(ret.get(1).get(position));
holder.text2.setText(ret.get(2).get(position));
//convertview.setBackgroundColor((position & 1) == 1 ?
Color.WHITE : Color.LTGRAY);
convertview.setBackgroundColor((position & 1) == 1 ?
Color.LTGRAY : Color.GREEN);
return convertview;
}
static class ViewHolder {
TextView text0;
TextView text1;
TextView text2;
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
Button getdata_btn;
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//getdata_btn = new Button(this);
//getdata_btn.setWidth(5);
//getdata_btn.setHeight(5);
//getdata_btn.setText("Press To Update");
l1 = (ListView) findViewById(R.id.ListView01);
//getdata_btn.setOnClickListener(this);
ColorDrawable divcolor = new
ColorDrawable(Color.RED);
//l1.addHeaderView(getdata_btn);
l1.setDivider(divcolor);
l1.setDividerHeight(2);
//layout1.addView(l1);
l1.setAdapter(new EfficientAdapter(this));
}
@Override
public void onClick(View v) {
l1.setAdapter(new EfficientAdapter(this));
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en