0

I have made an app in which i have an listView with JobCode and category.Now what i want to do is that when user click on a particular list item ,the full description on job should be displayed.But i dnt know hw to do it

Custom Adapter.Java

public class SearchJobsCustomList extends BaseAdapter implements View.OnClickListener {
    Context c;
    ArrayList<HashMap<String, String>> data;

    HashMap<String, String> resultp = new HashMap<String, String> ();
//    ArrayList<SearchValues> values;
//    SearchValues a;

    public SearchJobsCustomList(Context c, ArrayList<HashMap<String, String>> data) {
        super ();
        this.c = c;
        this.data = data;


    }

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

    @Override
    public Object getItem(int i) {
        return null;
    }

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

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {


        if (view == null) {
            view = LayoutInflater.from (c).inflate (R.layout.custom_search_jobs_lists, viewGroup, false);
            resultp = data.get (i);
            TextView JobCode = (TextView) view.findViewById (R.id.tv_job_code);
            TextView Category = (TextView) view.findViewById (R.id.tv_category);
            TextView ExpYrs = (TextView) view.findViewById (R.id.tv_exp_yrs);
            TextView ExpMnths = (TextView) view.findViewById (R.id.tv_exp_mnths);
            TextView Date = (TextView) view.findViewById (R.id.tv_date);
            Button bestCandidate = (Button) view.findViewById (R.id.bt_best_candidates);
            Button appliedJobs = (Button) view.findViewById (R.id.bt_applied_jobs);

            if (resultp.get ("counts").equals (0)) {
                bestCandidate.setFocusable (false);
                bestCandidate.setText (0);

            } else {
                bestCandidate.setText (resultp.get ("counts"));
            }

            if (resultp.get ("applied").equals (0)) {
                appliedJobs.setFocusable (false);
                appliedJobs.setText (0);

            } else {
                appliedJobs.setText (resultp.get ("applied"));
            }


            JobCode.setText (resultp.get ("code"));
            Category.setText (resultp.get ("category"));
            ExpYrs.setText (resultp.get ("minExp"));
            ExpMnths.setText (resultp.get ("maxExp"));
            Date.setText (resultp.get ("postedOn"));

            view.setOnClickListener (this);


        }
        return view;
    }

SearchJobList.Java

public class SearchJobsList extends Activity implements AdapterView.OnItemClickListener {


    private ListView lvresources;
    private Context c = this;
    SearchJobsCustomList searchJobsCustomList;


    @SuppressLint("NewApi")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate (savedInstanceState);
        getWindow ().requestFeature (Window.FEATURE_ACTION_BAR);
        getActionBar ().hide ();
        setContentView (R.layout.search_job_lists);
        initialize ();

    }


    private void initialize() {

        lvresources = (ListView) findViewById (R.id.listView);
        searchJobsCustomList = new SearchJobsCustomList (c, SearchJobs.arraylist);

        lvresources.setAdapter (searchJobsCustomList);
        lvresources.setOnItemClickListener (this);
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {



    value = data.get (i);
    Intent intent = new Intent (c, JobsDescription.class);
    intent.putExtra ("code", value.get ("code"));
    intent.putExtra ("category", value.get ("category"));
    intent.putExtra ("position", value.get ("position"));
    intent.putExtra ("desc", value.get ("desc"));
    intent.putExtra ("type", value.get ("type"));
    intent.putExtra ("hours", value.get ("hours"));
    intent.putExtra ("status", value.get ("status"));
    intent.putExtra ("expiryDate", value.get ("expiryDate"));
    intent.putExtra ("address", value.get ("address"));
    intent.putExtra ("state", value.get ("state"));
    intent.putExtra ("country", value.get ("country"));
    intent.putExtra ("city", value.get ("city"));
    intent.putExtra ("gender", value.get ("gender"));
    intent.putExtra ("religion", value.get ("religion"));
    intent.putExtra ("summary", value.get ("summary"));
    startActivity (intent);
    }
}

The arraylist contains all the job details.

Anuj
  • 129
  • 2
  • 14

1 Answers1

0

Are you trying to show the full job description in the same list or in a new activity?

New activity:
You are using resultp = data.get(i) to get the data. In the adapter. onItemClick() you can add the list position of the job to the intent using intent.putExtra("myJobID", i) and you can receive it when you start your job detail activity using getIntExtra. Then you can use that to search for the full job description like you search for the job details here. Or if the job description is just a string you can pass only that string. The context of your code will determine what is more appropriate.

Same list:
You can update the value of a list item as in this SO post. Put this code in your onItemClick(){} block.

Community
  • 1
  • 1
Umair Saad
  • 56
  • 7
  • @Umar Saad i m using different activity.see i edited my code but my list is not getting clicked – Anuj Jun 19 '14 at 09:55
  • Try setting up the `onClickListener` in your `initialize()` function. `lvresources.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView> adapterView, View view, int i, long l) { Log.d("Item being clicked!", Integer.toString(i)); } } });` Use LogCat to see if the item is being clicked. – Umair Saad Jun 19 '14 at 10:09
  • nw it is being clicked but nw i m getting 0 as the size of the data(which is the ArrayList) – Anuj Jun 19 '14 at 10:18
  • Are you sure there is data in the list? In `initialize()` add `Log.d("Job list length", Integer.toString(SearchJobs.arraylist.length));` to see if the problem is with the list or with the adapter. – Umair Saad Jun 19 '14 at 10:31