Android 如果字符串找不到该字符串,是否可以给它一个空值
如果xml中不存在空字符串,则可以随时创建它 例如,以下代码:-Android 如果字符串找不到该字符串,是否可以给它一个空值,android,string,Android,String,如果xml中不存在空字符串,则可以随时创建它 例如,以下代码:- super.onCreate(savedInstanceState); Bundle bundle = getIntent().getExtras(); String SManuf = bundle.getString("SManuf"); String manuf = bundle.getString("manuf"); String panel = bundle.getString("panel
super.onCreate(savedInstanceState);
Bundle bundle = getIntent().getExtras();
String SManuf = bundle.getString("SManuf");
String manuf = bundle.getString("manuf");
String panel = bundle.getString("panel");
setTitle("Instructions for "+manuf+" "+panel);
String Ins = (SManuf + panel+"Noof");
String InsI = (SManuf + panel);
// Toast.makeText(getApplicationContext(), Ins, Toast.LENGTH_SHORT).show();
int resId = getResources().getIdentifier(Ins, "string", getPackageName());
String InsNo = getResources().getString(resId);
scrollviewTerms = new ScrollView(this);
LinearLayout linearlayout = new LinearLayout(this);
linearlayout.setOrientation(LinearLayout.VERTICAL);
scrollviewTerms.addView(linearlayout);
//for (int i = 0; i < 13; i++)
int foo = Integer.parseInt(InsNo);
for (int i = 0; i < foo; i++)
{
LinearLayout linearManufTB = new LinearLayout(this);
linearManufTB.setOrientation(LinearLayout.HORIZONTAL);
linearlayout.addView(linearManufTB);
Termsb = new Button(this);
int id = getResources().getIdentifier("PanMansTitle" + i, "string", getPackageName());
String Terms = getResources().getString(id);
// Toast.makeText(getApplicationContext(), Terms, Toast.LENGTH_SHORT).show();
Termsb.setText(Terms);
Termsb.setId(i);
Termsb.setTextSize(30);
Termsb.setPadding(0, 0, 0, 0);
LinearLayout linearManufTV = new LinearLayout(this);
linearManufTV.setOrientation(LinearLayout.HORIZONTAL);
linearlayout.addView(linearManufTV);
String TermsS = Terms.replaceAll("&","").replaceAll(" ","").replaceAll("/","").replaceAll(" / ","").replaceAll("/ ","").replaceAll(" /","".replaceAll("&",""));
TermstINS = new TextView(this);
int ids = getResources().getIdentifier(InsI + TermsS, "string", getPackageName());
String TermsTV = getResources().getString(ids);
TermstINS.setText(TermsTV);
TermstINS.setId(i);
TermstINS.setTextSize(20);
TermstINS.setBackgroundColor(Color.parseColor("#999999"));
TermstINS.setPadding(0, 0, 0, 0);
LinearLayout linearManufTV2 = new LinearLayout(this);
linearManufTV2.setOrientation(LinearLayout.HORIZONTAL);
linearlayout.addView(linearManufTV2);
TermstNOTS = new TextView(this);
int idn = getResources().getIdentifier(InsI + TermsS +"N", "string", getPackageName());
String TermsTVN = getResources().getString(idn);
TermstNOTS.setText(TermsTVN);
TermstNOTS.setId(i);
TermstNOTS.setTextSize(20);
TermstNOTS.setBackgroundColor(Color.parseColor("#515151"));
TermstNOTS.setPadding(0, 0, 0, 0);
// b.setTypeface(Typeface.SERIF,Typeface.ITALIC);
Termsb.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
TermstINS.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
TermstNOTS.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
linearManufTB.addView(Termsb);
linearManufTV.addView(TermstINS);
linearManufTV2.addView(TermstNOTS);
if(TermstINS.length()== 0){ linearManufTB.setVisibility(View.GONE);linearManufTV.setVisibility(View.GONE);linearManufTV2.setVisibility(View.GONE);}else{
linearManufTB.setVisibility(View.VISIBLE); linearManufTV.setVisibility(View.GONE); linearManufTV2.setVisibility(View.GONE);}
super.onCreate(savedInstanceState);
Bundle Bundle=getIntent().getExtras();
String SManuf=bundle.getString(“SManuf”);
String manuf=bundle.getString(“manuf”);
String panel=bundle.getString(“panel”);
setTitle(“制造商+面板说明”);
字符串Ins=(SManuf+panel+“Noof”);
字符串InsI=(SManuf+面板);
//Toast.makeText(getApplicationContext(),Ins,Toast.LENGTH_SHORT.show();
int resId=getResources().getIdentifier(Ins,“string”,getPackageName());
String InsNo=getResources().getString(resId);
scrollviewTerms=新的ScrollView(此);
LinearLayout LinearLayout=新的LinearLayout(本);
linearlayout.setOrientation(linearlayout.VERTICAL);
scrollviewTerms.addView(linearlayout);
//对于(int i=0;i<13;i++)
intfoo=Integer.parseInt(InsNo);
for(int i=0;i
下面列出了标题和说明,以及下面的注释
但是,标题列表将标题0固定为标题200+,但并非所有系统都具有相同的标题,因为它们没有相同的功能,但会共享其中一些功能
与其在xml文件中键入200多条空白的指令和注释,还不如说该项当前不可用,而是动态生成一条空白
因此,它的行为更加智能,不需要输入大量死掉的数据
目前,任何没有指令的文件都不会显示标题(不是空的),或者指令和注释,但这需要我在没有指令和注释时为xml文件指令和注释创建数据条目
我相信这是基本的,但我找不到任何交叉参考。任何适当的例子或如何解决它的想法的帮助将不胜感激
String your_string = "";
这将为字符串提供一个“空”值
这将为您的字符串提供一个“空”值。getResources().getIdentifier(字符串名称、字符串定义类型、字符串定义包)
返回资源的id
。如果资源不存在,它将返回0
您可以这样更改代码:
String defaultString = "";
String Terms = id != 0 ? getResources().getString(id) : defaultString;
getResources().getIdentifier(字符串名称、字符串定义类型、字符串定义包)
返回资源的id
。如果资源不存在,它将返回0
您可以这样更改代码:
String defaultString = "";
String Terms = id != 0 ? getResources().getString(id) : defaultString;
适用于所有三个点,ids和idn,工作如梦。适用于所有三个点,ids和idn,工作如梦。