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(),但仍然没有用。我究竟做错了什么?
2 回答
皈依舞
TA贡献1851条经验 获得超3个赞
改变
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]);
慕田峪7331174
TA贡献1828条经验 获得超13个赞
尝试使用getResources()
方法获取您的字符串:
String yourString = context.getResources().getString(R.string.yourResource);
添加回答
举报
0/150
提交
取消