Question is i'm trying to update all the buttons in by listview, buttons are in CustomAdapter which i've written, but buttons are not being updated. So the idea is to change the text of all buttons in the ListView and show the timer after button was clicked, can anyone tell what i'm doing wrong? Here's the code:
public class CustomAdapter extends BaseAdapter {
Context context;
LayoutInflater inflater;
ArrayList<HashMap<String, String>> data;
ImageLoader imageLoader;
HashMap<String, String> resultp = new HashMap<String, String>();
int secs, mins;
public CustomAdapter(Context context,
ArrayList<HashMap<String, String>> arraylist) {
this.context = context;
data = arraylist;
imageLoader = new ImageLoader(context);
}
@Override
public int getCount() {
return data.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
public View getView(final int position, View convertView, ViewGroup parent) {
final Button buttonShare;
TextView title;
ImageView poster;
View itemView = null;
if (convertView == null) {
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
itemView = inflater.inflate(R.layout.ads_layout, parent, false);
} else {
itemView = convertView;
}
resultp = data.get(position);
// Настраиваем текстовые поля
title = (TextView) itemView.findViewById(R.id.title);
buttonShare = (Button) itemView.findViewById(R.id.postButton);
// ImageView
poster = (ImageView) itemView.findViewById(R.id.adImage);
title.setText(resultp.get(AdsFragment.TAG_TITLE));
imageLoader.DisplayImage(resultp.get(AdsFragment.TAG_PHOTO), poster);
buttonShare.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Boolean posted = AdsFragment.getPosted();
if (posted == false) {
context.startService(new Intent(context, BroadcastService.class));
Log.i("SERVICE", "Started service");
cdt.start();
//updateGUI(buttonShare);
} else {
Log.i("POST", "WAS POSTED!!!");
new AlertDialog.Builder(context).setTitle("LALKA")
.setMessage("LALKA").setCancelable(true).show();
}
}
});
CountDownTimer cdt = new CountDownTimer(20000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
secs = (int) (millisUntilFinished / 1000);
mins = secs / 60;
secs = secs % 60;
buttonShare.setText(" " + mins + " : " + String.format("%02d", secs));
}
@Override
public void onFinish() {
}
};
return itemView;
}
}