Go to another Activity from a list item with parse.com site data

Asked

Viewed 1,436 times

2

I would like to know how I could do to call another Activity, through a list item where the data is used from the site parse.com. For example, I have this code:

public class ListViewAdapterPizzarias extends BaseAdapter {

// Declare Variables

Context context;
LayoutInflater inflater;
ImageLoader imageLoader;
private List<WorldPopulation> worldpopulationlist = null;
private ArrayList<WorldPopulation> arraylist;

public ListViewAdapterPizzarias(Context context,
                                List<WorldPopulation> worldpopulationlist) {
    this.context = context;
    this.worldpopulationlist = worldpopulationlist;
    inflater = LayoutInflater.from(context);
    this.arraylist = new ArrayList<WorldPopulation>();
    this.arraylist.addAll(worldpopulationlist);
    imageLoader = new ImageLoader(context);
}

public class ViewHolder {

    TextView nome;
    TextView telefone;
    TextView endereco;
    TextView status;
}

@Override
public int getCount() {
    return worldpopulationlist.size();
}

@Override
public Object getItem(int position) {
    return worldpopulationlist.get(position);
}

@Override
public long getItemId(int position) {
    return position;
}

public View getView(final int position, View view, ViewGroup parent) {
    final ViewHolder holder;
    if (view == null) {
        holder = new ViewHolder();

        view = inflater.inflate(R.layout.item_lista_pizzarias, null);
        // Locate the TextViews in listview_item.xml
        holder.nome = (TextView) view.findViewById(R.id.nome);
        holder.endereco = (TextView) view.findViewById(R.id.endereco);
        holder.telefone = (TextView) view.findViewById(R.id.telefone);
        holder.status = (TextView) view.findViewById(R.id.status);
        view.setTag(holder);


    } else {
        holder = (ViewHolder) view.getTag();
    }
    // Set the results into TextViews

    holder.nome.setText(worldpopulationlist.get(position).getNome());
    holder.endereco.setText(worldpopulationlist.get(position).getEndereco());
    holder.telefone.setText(worldpopulationlist.get(position).getTelefone());
    holder.status.setText(worldpopulationlist.get(position).getStatus());


    ///teste
    // Listen for ListView Item Click
    view.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // Send single item click data to SingleItemView Class
            Intent intent = new Intent(context, MainActivity.class);

   //O que colocar aqui para buscar o dado do site parse.com e chamar a outra activity?

        }
    });
    return view;
}

}
  • Your difficulty lies in knowing how to create a task with Asynctask to call the service, how to pass something from a Activity to another or what exactly?

  • @Paulo Rodrigues. I have an Activity that contains a listview that has your data stored on the site parse.com. The problem is I have an Activity with the name of the pizzerias on a list and I also have an Activity with the menu of each pizzeria. Hence what happens is that I cannot associate the data that is pulled from parse.com to call the correct Activity. For example, a list with several names of Pizzerias: PIZZERIA CAPRICHO calls Activity MENU CAPRICHO and PIZZERIA FAT calls Activity MENU FAT...

1 answer

0

It is not interesting that you perform this logic inside your Adapter. From your Listview you have the method setOnItemClickListener which is the best way to perform an action from clicking on a list item.

To start an Activity you need another Activity to create one Intent and use startActivity(), for example:

Intent i = new Intent(MyActivity.this, MyNewActivity.class);
startActivity(i);

If you are using your Listview in a Fragment use the method getActivity() to create Intent, for example:

Intent i = new Intent(getActivity(), MyNewActivity.class);
getActivity().startActivity(i);
  • See the above question I commented on. See if you understand.

  • I think I understand what you need. I will explain to you a form of implementation for a scenario like yours, however your question is very broad, there is no way to explain everything here. If you have an Activity with data loaded into a list from a Server, very likely you mount this list with classes (Models in the MVC standard) and each Model has an identifier (ID, Code, Etc). When you click on a list item you can pick up your Model through the method I mentioned, setOnItemClickListener, and so you call another service by passing the identifier of your Model.

  • Wouldn’t you have any example like what I’m trying to do? The way you spoke I already understood, what is missing is to see how I could make this implementation.

  • There’s no way to write it all down here. You can see how it works by studying a similar project, for example: https://github.com/ogrebgr/android_volley_examples

  • 1

    Thanks for the answer, that’s what I’m looking for, I’m solving the problem, if it works out, I’ll mark as solved, I’m still implementing to my problem. Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.