我想将自定义ArrayAdapter中的HashMap或ArrayList对象传递给填充ListView的活动。我想发送已检查的记录recordId字段。我是新的Android.Any Suggestion Plz
答案 0 :(得分:1)
将适配器传递给活动。然后在适配器可以调用的活动中提供一个方法。
在适配器中:
private MyActivity activity;
public void setActivity(MyActivity activity) {
this.activity = activity;
}
活动:
// create adapter
adapter.setActvity(this);
在适配器中(当您想将参数传递回活动时):
activity.setHashMap(mymap);
答案 1 :(得分:0)
我的CustomAdapter类::
class SearchResultAdapter扩展了ArrayAdapter {
Context context;
int layoutResourceId;
private ArrayList<SearchResultModel> results;
public SearchResultAdapter(Context context, int layoutResourceId, ArrayList<SearchResultModel> results) {
super(context, layoutResourceId, results);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.results = results;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View row = convertView;
SearchResultHolder holder=null;
if(row == null)
{
LayoutInflater vi = ((Activity)context).getLayoutInflater();
row = vi.inflate(R.layout.listitemrow, null);
holder = new SearchResultHolder();
holder.jobdetails = (TextView)row.findViewById(R.id.jobdetails);
row.setTag(holder);
}
else
{
holder = (SearchResultHolder)row.getTag();
}
SearchResultModel model = results.get(position);
if (model != null)
{
row.setId(Integer.parseInt(model.getjob_id()));
String result=
"<font color=#5D2E8C>"+model.getjob_title()+"</font><br>" +
"<font color=#737373>"+model.getpost_date()+"</font><br>"+model.getuser_name()+"<br>" +
"<font color=#3C5A98>"+model.getsalary()+" Rs (Per Annum)</font><br>"+
"<font color=#97AB40>"+model.getjob_location()+"," +
" "+model.getjob_exp_min()+"-"+model.getjob_exp_max()+" year";
holder.jobdetails.setText(Html.fromHtml(result));
}
return row;
}
class SearchResultHolder
{
TextView jobdetails;
}
}
我将使用Above ArrayAdapter的主方法中的ListView。
SearchResultAdapter adapter;
ListView lv;
adapter=new SearchResultAdapter(this, R.layout.listitemrow, model);
//Here model is the ArrayList<SearchResultModel>
lv=getListView();
lv.setAdapter(adapter);
lv.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> arg0, View v,int arg2, long arg3)
{
}
}
我的SearchResultModel类
package com.cws.model;
public class SearchResultModel {
private String job_id,userdetail_id,user_name,subuser_id,
job_title,search_keyword,job_skill,
job_exp_min,job_exp_max,
job_description,salary,
job_location,education,
industry_id,role_id,functional_id,job_type,
desire_candiadate_profile,company_profile,
website,executive_name,address,email,
phone,post_date,is_active;
private String count,counter;//----count=total no of row found
//---counter=now displaying row nos.
private String errorflag;
public void seterrorflag(String errorflag)
{
this.errorflag=errorflag;
}
public String geterrorflag()
{
return this.errorflag;
}
public void setcount(String count)
{
this.count=count;
}
public String getcount()
{
return this.count;
}
public void setcounter(String counter)
{
this.counter=counter;
}
public String getcounter()
{
return this.counter;
}
public void setjob_id(String job_id)
{
this.job_id=job_id;
}
public String getjob_id()
{
return this.job_id;
}
public void setuserdetail_id(String userdetail_id){
this.userdetail_id=userdetail_id;
}
public String getuserdetail_id()
{
return this.userdetail_id;
}
public void setuser_name(String user_name){
this.user_name=user_name;
}
public String getuser_name()
{
return this.user_name;
}
public void setsubuser_id(String subuser_id){
this.subuser_id=subuser_id;
}
public String getsubuser_id()
{
return this.subuser_id;
}
public void setjob_title(String job_title){
this.job_title=job_title;
}
public String getjob_title()
{
return this.job_title;
}
public void setsearch_keyword(String search_keyword){
this.search_keyword=search_keyword;
}
public String getsearch_keyword()
{
return this.search_keyword;
}
public void setjob_skill(String job_skill){
this.job_skill=job_skill;
}
public String getjob_skill()
{
return this.job_skill;
}
public void setjob_exp_min(String job_exp_min){
this.job_exp_min=job_exp_min;
}
public String getjob_exp_min()
{
return this.job_exp_min;
}
public void setjob_exp_max(String job_exp_max){
this.job_exp_max=job_exp_max;
}
public String getjob_exp_max()
{
return this.job_exp_max;
}
public void setjob_description(String job_description){
this.job_description=job_description;
}
public String getjob_description()
{
return this.job_description;
}
public void setsalary(String salary){
this.salary=salary;
}
public String getsalary()
{
return this.salary;
}
public void setjob_location(String job_location){
this.job_location=job_location;
}
public String getjob_location()
{
return this.job_location;
}
public void seteducation(String education){
this.education=education;
}
public String geteducation()
{
return this.education;
}
public void setindustry_id(String industry_id){
this.industry_id=industry_id;
}
public String getindustry_id()
{
return this.industry_id;
}
public void setrole_id(String role_id){
this.role_id=role_id;
}
public String getrole_id()
{
return this.role_id;
}
public void setfunctional_id(String functional_id){
this.functional_id=functional_id;
}
public String getfunctional_id()
{
return this.functional_id;
}
public void setjob_type(String job_type){
this.job_type=job_type;
}
public String getjob_type()
{
return this.job_type;
}
public void setdesire_candiadate_profile(String desire_candiadate_profile){
this.desire_candiadate_profile=desire_candiadate_profile;
}
public String getdesire_candiadate_profile()
{
return this.desire_candiadate_profile;
}
public void setcompany_profile(String company_profile){
this.company_profile=company_profile;
}
public String getcompany_profile()
{
return this.company_profile;
}
public void setwebsite(String website){
this.website=website;
}
public String getwebsite()
{
return this.website;
}
public void setexecutive_name(String executive_name){
this.executive_name=executive_name;
}
public String getexecutive_name()
{
return this.executive_name;
}
public void setaddress(String address){
this.address=address;
}
public String getaddress()
{
return this.address;
}
public void setemail(String email){
this.email=email;
}
public String getemail()
{
return this.email;
}
public void setphone(String phone){
this.phone=phone;
}
public String getphone()
{
return this.phone;
}
public void setpost_date(String post_date){
this.post_date=post_date;
}
public String getpost_date()
{
return this.post_date;
}
public void setis_active(String is_active){
this.is_active=is_active;
}
public String getis_active()
{
return this.is_active;
}
}