1
I have the following code, which shows the items in a list, on the screen:
Activity:
public class InviteActivity extends ListActivity implements InviteView
{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_invite);
setListAdapter(new InvitePresenter(this));
}
@Override
public Context getContext(){
return this;
}
}
Adapter:
public class InvitePresenter extends BaseAdapter {
private InviteView inviteView;
private List<UserCommunity> usersList = new ArrayList<UserCommunity>();
public InvitePresenter(InviteView inviteView){
this.inviteView = inviteView;
RequestManager.Users(new FutureCallback<JsonObject>() {
@Override
public void onCompleted(Exception e, JsonObject result) {
usersList = new Gson().fromJson(result.get("data"), new TypeToken<ArrayList<UserCommunity>>() {}.getType());
if (usersList != null) {
notifyDataSetChanged();
}
}
});
}
@Override
public int getCount() {
return usersList.size();
}
@Override
public Object getItem(int position) {
return usersList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//recupera o estado da posição atual
UserCommunity inviteUsers = usersList.get(position);
//Cria uma instancia do layout .. na view
LayoutInflater inflater = (LayoutInflater)inviteView.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.item_invite_listview,null);
TextView txt_Nome = (TextView)view.findViewById(R.id.txt_nome_invite);
TextView txt_Email = (TextView)view.findViewById(R.id.txt_email_invite);
TextView txt_Distancia = (TextView)view.findViewById(R.id.txt_distancia_invite);
txt_Nome.setText(inviteUsers.name);
txt_Email.setText(inviteUsers.email);
txt_Distancia.setText(Integer.toString(inviteUsers.distance));
return view;
}
}
I would like to implement a click on a list item. Then a new Activity will be opened.
Activity code is just this, listview is only xml, I can put it
– Henrique
Assemble everything in the presenter, q inherits from the Adapter, and return to the view(Activity)
– Henrique
@Henriquemendes but the Click System on the item is in Activity or Listview’s "father" Ragment. There was some doubt?
– leofontes
No, I do. Thank you very much!
– Henrique