Wants a custom page to display employee detailed profile when clicked on listview employee

347 views Asked by At

I have one custom list for displaying employee pic and name and i want to navigate to next activity when list item is clicked, In next activity i want to display details of employee dynamically from web service!! how to do that please give some idea or link??

thank you in advance!

1

There are 1 answers

2
James On

That's a very broad question which will take a long time to answer. There are a few ways you could do it, but hopefully this short answer will help and at least point you in a direction.

I'm guessing you already have an adapter with a list of all employees (List or whatever) powering your listview. You should create a public method in your adapter to take in the position, and return a unique id referencing your employee. Note a unique id is not necessarily the same as the position of the item.

Here's a crude example:

public int getUniqueId(int position){
    Employee employee = mAllItems.get(position);

    if(employee != null){
        return employee.getUniqueId();
    }
    //Couldn't find
    return 0;
}

Then implement an onItemClickListener on your listview. The method can then call the adapter to retrieve a unique id. This unique ID is what you would pass via intent to your new activity. Your new activity will lookup the employee details and display them.

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    int uniqueId = mAdapter.getUniqueId(position);

    if(uniqueId > 0) {
        Intent i = new Intent(this, ActivityEmployeeDetails.class);
        i.putExtra(ActivityEmployeeDetails.TAG_UNIQUE_ID, uniqueId);
        startActivity(i);
    }
}

Hope this helps.