0

Perhaps you will find the question that I'm going to ask to be too mainstream/basic. But I need help maybe I'm a newbie. Basically I'm making a simple app that displays maps about some tourist places in an offline manner.It has three activities. A - expandable list B - activity that displays a map using a webview C - TabHost that hosts the Activity B.

Whenever a child is clicked from the expandable list in the Activity A it sends two intents. 1) To Activity B giving the location of the desired map. 2) To Activity C to start the TabHost. Code is as follows:

 if (childclicked=="Red Fort")
            {
                Intent toMap =  new Intent(TourList.this,Map.class);
                toMap.putExtra(ID , "file:///android_asset/redfort.jpg");

                Intent i = new Intent(TourList.this,TourTabs.class);
                startActivity(i);


            }

and the code in the activity B is as follows:

public class Map extends Activity {
String imageUrl;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map);


    //Using a webview for pinch zooming
    WebView vw=(WebView)findViewById(R.id.webView1);
    vw.getSettings().setBuiltInZoomControls(true);      

    //Fetching intents
    Intent fromList = getIntent();



  imageUrl = fromList.getStringExtra(TourList.ID);
   vw.loadUrl(imageUrl);
}

But the bug is runtime. Nothing gets displayed in the TabHost. The WebView does not display anything. Why? Please help.

4

2 回答 2

4
 if (childclicked=="Red Fort")
 {
    Intent toMap =  new Intent(TourList.this,Map.class);
    toMap.putExtra(ID , "file:///android_asset/redfort.jpg");

    Intent i = new Intent(TourList.this,TourTabs.class);
    startActivity(i);

 }

字符串无法==在 java 中进行比较。您必须使用 equals 或 equalsIgnoreCase

 if (childclicked.equals("Red Fort"))

在 if 正文中,您创建了两个不同的Intent. 在其中一个中放置一个字符串并使用另一个来启动一个 Activity。第一个没用

于 2013-05-15T15:58:19.070 回答
0

您已经在意图中正确传递了该值,但我认为您已经开始了第二个意图的活动,在该活动中您没有传递任何内容,并且您正试图从TourList.ID尚未传递的活动中访问该值。

尝试如下并尝试运行活动Map.java然后访问该值。

 if (childclicked.equals("Red Fort"))
  {
     Intent toMap =  new Intent(TourList.this,Map.class);
     toMap.putExtra(ID , "file:///android_asset/redfort.jpg");
   startActivity(toMap);

   Intent i = new Intent(TourList.this,TourTabs.class);
    startActivity(i);

 }

还要根据我所做的更改 if 条件。我希望它会帮助你。

于 2013-05-15T16:02:46.077 回答