package com.example.android.booklisting;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class SliderAdapter extends PagerAdapter {
Context context;
LayoutInflater layoutInflater;
public SliderAdapter(Context context) {
this.context = context;
}
public String[] slide_headings = {
context.getString(R.string.onboard1Header),
context.getString(R.string.onboard2Header),
context.getString(R.string.onboard3Header)
};
}
我尝试传递上下文,还尝试了getResources()。getString(),但仍然无法正常工作。我在做什么错了?
答案 0 :(得分:0)
尝试使用getResources()
方法获取字符串:
String yourString = context.getResources().getString(R.string.yourResource);
答案 1 :(得分:0)
更改
public String[] slide_headings = {
context.getString(R.string.onboard1Header),
context.getString(R.string.onboard2Header),
context.getString(R.string.onboard3Header)
};
收件人
private int[] slide_headings = {
R.string.onboard1Header,
R.string.onboard2Header,
R.string.onboard3Header
};
并像这样使用它:
String yourString = context.getResources().getString(slide_headings[yout_index]);