我使用GridView
創建了本週的視圖。我使用BaseAdapter
來生成GridView
。無法從gridView獲取對象
這是我給的值到GridView
ArrayList<WeekCellItem> weekCellItems = getData(scheduleListdto);
gridview1.setAdapter(new WeekAdapter(getApplicationContext(),weekCellItems));
而且我需要在CurrentItem
當現在的位置是我上的GridView
每個小區點擊。
我寫的onItemClickListener
爲GridView
gridview1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Object o= gridview1.getItemAtPosition(arg2);
Log.e("", "hhh");
}
});
我得到的對象 'O' 爲空。
(EDIT)
我weekAdapter
public class WeekAdapter extends BaseAdapter
{
Context mycontext;
ArrayList<String>weekHeads;
ArrayList<WeekCellItem> weekCellItems;
LayoutInflater inflater;
public WeekAdapter(Context c, ArrayList<WeekCellItem> items, ArrayList<String> obj)
{
weekCellItems=items;
weekHeads=obj;
mycontext=c;
inflater = LayoutInflater.from(c);
}
public int getCount() {
// TODO Auto-generated method stub
return weekCellItems.size();
}
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
public View getView(int pos, View convertview, ViewGroup parent) {
// TODO Auto-generated method stub
viewHolder holder = new viewHolder();
if(convertview==null)
{
convertview = inflater.inflate(R.layout.weekly_layout, null);
holder.tv = (TextView) convertview.findViewById(R.id.textweeklylayout);
convertview.setTag(holder);
}
else
holder=(viewHolder)convertview.getTag();
return convertview;
}
private static class viewHolder
{
TextView tv;
}}
顯示您的WeekAdapter代碼 – 2013-04-24 05:08:35
非常老的問題 – Trikaldarshi 2013-04-24 05:08:37
創建自定義適配器 – Trikaldarshi 2013-04-24 05:08:55