Ye *_*ung 0 android android-intent
我有两个这样的String Arrays,
String[] htmlArray = {
"file:///android_asset/Pinocchio/OPS/chapter-001.xml",
"file:///android_asset/Pinocchio/OPS/chapter-002.xml",
"file:///android_asset/Pinocchio/OPS/chapter-035.xml",
"file:///android_asset/Pinocchio/OPS/chapter-035.xml"
};
String[] htmlArray1 = {
"file:///android_asset/Harry_Potter/OEBPS/part1.xhtml",
"file:///android_asset/Harry_Potter/OEBPS/part2_split_000.xhtml",
"file:///android_asset/Harry_Potter/OEBPS/part18_split_000.xhtml",
"file:///android_asset/Harry_Potter/OEBPS/part18_split_001.xhtml",
};
Run Code Online (Sandbox Code Playgroud)
然后,我把两个ImageView放在另一个类中,
private void init() {
pino_cover = (ImageView) findViewById(R.id.pino_cover);
pino_cover.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent reader=new Intent(instance,ReaderScreen.class);
reader.putExtra("pino",true);
startActivity(reader);
}
});
harry_cover=(ImageView) findViewById(R.id.harry_cover);
harry_cover.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent reader=new Intent(instance,ReaderScreen.class);
reader.putExtra("harry",true);
startActivity(reader);
}
});
}
Run Code Online (Sandbox Code Playgroud)
然后,如果我点击Pino图像,我可以通过htmlArray获取数据.
Intent i=getIntent();
Bundle b = i.getExtras();
String newText = b.
String setext=b.getString("harry");
if (newText=="pino")
pages = htmlArray;
else
pages = htmlArray1;
Run Code Online (Sandbox Code Playgroud)
但是,如果我点击Harry图像,那么它也会被用来获取数据htmlArray.我想得到htmlArray1.我怎么能得到?
你只是为你的意图添加一个布尔值,但是你可以使用.putExtra(mStringArray, htmlArray1);这个方法存在来通过意图传递数组......?另外,比较在Java中的两个字符串,你不能这样做==,但.equals("").在你的情况下if(newText.equals("harry))......
编辑 好了,在一个更简单的版本中,你有:
Intent i=getIntent();
Bundle b = i.getExtras();
String newText = b.
String setext=b.getString("harry");
if (newText=="pino")
pages = htmlArray;
else
pages = htmlArray1;
Run Code Online (Sandbox Code Playgroud)
替换它:
Intent i=getIntent();
Bundle b = i.getExtras();
String newText = b.
String setext=b.getString("harry");
if (newText.equals("pino"))
pages = htmlArray;
else
pages = htmlArray1;
Run Code Online (Sandbox Code Playgroud)
这应该在逻辑上有效.
| 归档时间: |
|
| 查看次数: |
869 次 |
| 最近记录: |