gpt4 book ai didi

android - 从多个项目 ListView 获取数据?

转载 作者:行者123 更新时间:2023-11-30 04:25:55 26 4
gpt4 key购买 nike

我正在尝试从多项目 ListView 中获取数据,但是当我尝试使用 onListItemClick 时,我总是遇到错误。

它似乎在要求我创建方法时:

i.putExtra("title", this.getItem(position).getTitle());

被调用。

    public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
mInflater = (LayoutInflater) getSystemService(
Activity.LAYOUT_INFLATER_SERVICE);
data = new Vector<RowData>();
for(int i=0;i<title.length;i++){
try {
rd = new RowData(i,title[i],detail[i]);
} catch (ParseException e) {
e.printStackTrace();
}
data.add(rd);
}
CustomAdapter adapter = new CustomAdapter(this, R.layout.list, R.id.title, data);
setListAdapter(adapter);
getListView().setTextFilterEnabled(true);
}


public void onListItemClick(ListView parent, View v, int position,
long id) {


Intent i = new Intent(this,ShowDetails.class);
Bundle bundle = new Bundle();
i.putExtra("title", this.getItem(position).getTitle());
i.putExtra("title", this.getItem(position).getDetail());
setResult(ShowDetails.RESULT_OK, i);
finish();
}


private class CustomAdapter extends ArrayAdapter<RowData> {
public CustomAdapter(Context context, int resource,
int textViewResourceId, List<RowData> objects) {
super(context, resource, textViewResourceId, objects);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
TextView title = null;
TextView detail = null;
ImageView i11=null;
RowData rowData= getItem(position);
if(null == convertView){
convertView = mInflater.inflate(R.layout.list, null);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
}
holder = (ViewHolder) convertView.getTag();
title = holder.gettitle();
title.setText(rowData.mTitle);
detail = holder.getdetail();
detail.setText(rowData.mDetail);
i11=holder.getImage();
i11.setImageResource(imgid[rowData.mId]);
return convertView;
}
private class ViewHolder {
private View mRow;
private TextView title = null;
private TextView detail = null;
private ImageView i11=null;
public ViewHolder(View row) {
mRow = row;
}
public TextView gettitle() {
if(null == title){
title = (TextView) mRow.findViewById(R.id.title);
}
return title;
}
public TextView getdetail() {
if(null == detail){
detail = (TextView) mRow.findViewById(R.id.detail);
}
return detail;
}
public ImageView getImage() {
if(null == i11){
i11 = (ImageView) mRow.findViewById(R.id.img);
}
return i11;
}
}

最佳答案

首先,您有 gettitle() 方法,而不是适配器中定义的 getTitle()。

getTitle() 是适配器的一种方法。 getItem(position) 返回一个 RowData 类型的对象,它没有这样的方法。

此外,getTitle() 返回一个 TextView。您确定要通过 Intent 或此 TextView 的字符串传递 TextView 吗?

关于android - 从多个项目 ListView 获取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8523567/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com