I made a% of% of that% of% of% with%. My layout contains only a set of Adapter
, one below the other, very simple.
I want any system event to be watched by my extends
and that a certain item in the list is changed. For this I am using ArrayAdapter
.
In the constructor of my TextViews
I use Adapter
The Adapter has a EventBus
method
I created a Job to run and test, it runs Adapter
when it finishes, and using EventBus.getDefault().register(this);
I can confirm that the onEvent(MessageRunTask event){...}
EventBus.getDefault().post(new MessageRunTask(r));
is running successfully.
What I do not know how to do is:
In the Log.i
method, how do I get the item X from the list and update the onEvent
property of the Adapter
Y that is within that item X?
UPDATE 1:
Follow the code of onEvent
with the tried solutions:
public class TarefaAdapter extends ArrayAdapter<Tarefa> {
private List<Tarefa> items;
private int layoutResourceId;
private Context context;
private List<View> itensExibidos;
public TarefaAdapter(Context context, int layoutResourceId, List<Tarefa> items) {
super(context, layoutResourceId, items);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.items = items;
this.itensExibidos = new ArrayList<View>();
EventBus.getDefault().register(this);
}
public void onEvent(MessageRunTask event){
if (!itensExibidos.isEmpty()) {
//ESSE LOG APARECE
Log.i("DEBUGEVENT", " teste");
//TENTATIVA 1
View v = itensExibidos.get(0);
TarefasHolder ta = (TarefasHolder) v.getTag();
ta.url.setText("Teste texto");
//TENTATIVA 2
TextView t = (TextView)v.findViewById(R.id.lblURL);
t.setText("Teste texto");
//TENTATIVA 3
Tarefa teste = this.items.get(0);
teste.url = "Teste texto";
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
TarefasHolder holder = null;
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new TarefasHolder();
holder.tarefa = items.get(position);
holder.removePaymentButton = (Button)row.findViewById(R.id.btnExcluir);
holder.removePaymentButton.setTag(holder.tarefa);
holder.url = (TextView)row.findViewById(R.id.lblURL);
holder.status = (TextView)row.findViewById(R.id.lblStatus);
holder.lastexecute = (TextView)row.findViewById(R.id.lblLastExecute);
holder.connectivity = (TextView)row.findViewById(R.id.lblConnectivity);
holder.idle = (TextView)row.findViewById(R.id.lblIdle);
holder.charging = (TextView)row.findViewById(R.id.lblCharging);
holder.delay = (TextView)row.findViewById(R.id.lblDelay);
row.setTag(holder);
setupItem(holder);
itensExibidos.add(row);
return row;
}
private void setupItem(TarefasHolder holder) {
holder.url.setText(holder.tarefa.url);
holder.status.setText(trataStatus(holder.tarefa.status));
holder.lastexecute.setText(trataData(holder.tarefa.lastexecute));
holder.charging.setText(trataCharging(holder.tarefa.charging));
holder.idle.setText(trataIdle(holder.tarefa.idle));
holder.delay.setText(trataDelay(holder.tarefa.periodic));
holder.connectivity.setText(trataNetworkType(holder.tarefa.networktype));
}
public static class TarefasHolder{
Tarefa tarefa;
TextView url;
TextView status;
TextView lastexecute;
TextView connectivity;
TextView delay;
TextView charging;
TextView idle;
Button removePaymentButton;
}
}
These are the attempts I've made.