我是Android開發的新手,我已經學習了大約4個月。如何在這種情況下獲得應用程序上下文?
我想讓我的應用程序上下文使用名爲畢加索的庫。我構建了一個服裝適配器來將圖像加載到我的imageview。
但我有一些問題得到的應用程序上下文,我試圖使用getBaseContext,getActivity(),並創建了一個變量來獲取上下文,但它沒有奏效。
我建設使用片段我的應用程序,我的代碼:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_one, container, false);
final ArrayList alEvents = new ArrayList<String>();
eventsAdapter = new costumeadapter(getActivity(), alEvents,
R.layout.list, new String[] { ITEM_NAME, ITEM_EVENT },
new int[] { R.id.name, R.id.current_event });
lvEvents.setAdapter(eventsAdapter);
...
}
我的服裝適配器:
public class costumeadapter extends SimpleAdapter {
Context context;
public costumeadapter(FragmentActivity fragmentActivity,
List<? extends Map<String, ?>> data, int resource, String[] from,
int[] to) {
super(fragmentActivity, data, resource, from, to);
// TODO Auto-generated constructor stub
}
public View getView(final int position, final View convertView,
final ViewGroup parent) {
View v = super.getView(position, convertView, parent);
ImageView bg_image = (ImageView) v.findViewById(R.id.bg_image);
Picasso.with(context)
.load("http://pplware.sapo.pt/wp-content/uploads/2015/06/Wallpaper_10.jpg")
.into(bg_image);
return v;
}
}
你們能不能給我任何解決辦法嗎?謝謝。
您是否嘗試過'getApplicationContext();'? – George
我試過了,我收到了這個警告:方法getApplicationContext()未定義類型costumeadapter –