对不起,这里只有一个菜鸟,我的老板从前开发者那里把这个交给我,我对于android没什么好看的。我的问题是如何在getView
>中传递额外的动态值? onClick
方法让我可以访问。
categoryCursorAdaptor
class categoryCursorAdaptor extends BaseAdapter {
Context context;
String[] data;
private static LayoutInflater inflater = null;
public categoryCursorAdaptor(Context context, String[] data) {
this.context = context;
this.data = data;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return data.length;
}
@Override
public Object getItem(int position) {
return data[position];
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
if (vi == null) vi = inflater.inflate(R.layout.item_category, null);
TextView text = (TextView) vi.findViewById(R.id.specialCatItemName);
text.setText(data[position]);
Button Button1= (Button) vi.findViewById(R.id.btnSpecialView);
Button1.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
//Access extra values here
}
});
return vi;
}
}
CategoryActivity
String[] catValsArr = new String[arrayCatVals.size()];
catValsArr = arrayCatVals.toArray(catValsArr);
lvSpecialCatList = (ListView) findViewById(R.id.lvSpecialCatList);
lvSpecialCatList.setAdapter(new categoryCursorAdaptor(this, catValsArr));
答案 0 :(得分:2)
position
内已有getView(....)
,因此请使用此String Array
String myData = data[position]; //Use myData
<{1>} 下的