单击列表打开作业详细信息

时间:2014-06-19 08:04:35

标签: android listview

我已经创建了一个应用程序,其中我有一个带有JobCode和category的listView。现在我想要做的是,当用户点击特定列表项时,应该显示工作的完整描述。但我知道hw这样做

自定义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);
    }
}

arraylist包含所有工作细节。

1 个答案:

答案 0 :(得分:0)

您是否尝试在同一列表或新活动中显示完整的职位描述?

新活动:
您正在使用resultp = data.get(i)来获取数据。在adapter. onItemClick()中,您可以使用intent.putExtra("myJobID", i)将作业的列表位置添加到意图中,并且可以在使用getIntExtra开始作业详细信息活动时收到该位置。然后,您可以使用它来搜索完整的职位描述,就像您在此处搜索职位详细信息一样。或者,如果作业描述只是一个字符串,则只能传递该字符串。代码的上下文将决定什么更合适。

相同列表:
您可以按照此SO post更新列表项的值。将此代码放在onItemClick(){}块中。