开发者

Map activity not get called on List Item Click Listener

I have to call mapactivity from list activity.whenever user click on item on listview, map activity should get fire.But when item is clickd i m getting exception that your map activity class not found.

if i place simple acitivity insted of map activity..my code worked well..i dont know why the exception is raised

here is my code.

XML FIle

<?xml version="1.0" encoding="utf-8"?>

            <!--Header -->
<LinearLayout android:id="@+id/Header" 
            android:background="#EE7621" 
            android:layout_width="fill_parent"
             android:layout_height="35dip" android:orientation="horizontal">

    <Button android:id="@+id/backPantries" 
            android:background="@drawable/pantryback"
            android:layout_marginTop="2dip" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content">
    </Button>


</LinearLayout>

 <TextView android:textColor="#00AF33" android:background="#FFFFFF" android:text="pantryNameOnMap" android:id="@+id/pantryNameOnMap" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="15dip"></TextView>

<LinearLayout 
            android:layout_width="fill_parent"
             android:layout_height="wrap_content">

  <com.google.android.maps.MapView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/singlePantry"
         android:layout_width="fill_parent"
        android:layout_height="390dip"
         android:gravity="center" 
        android:clickable="true"
        android:apiKey="016JeH4RyEu_PJVdseJdN45AnkUvFrjE6gwLh9w"/>



</LinearLayout>

<TextView android:textColor="#00AF33" android:background="#FFFFFF" android:text="pantryPhNoOnMap" android:id="@+id/pantryPhNoOnMap" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:textSize="15dip"></TextView>


<LinearLayout android:id="@+id/linearLayout1" 
            android:background="@drawable/footer"
             android:gravity="bottom" 
             android:orientation="vertical"
              android:layout_width="wrap_content"
               android:layout_height="wrap_content">
</LinearLayout>

HERE IS MY JAVA FILE

 package com.example;

import java.net.URL;
import java.util.ArrayList;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;



import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class OnlineUsersList extends ListActivity
{
    public static ArrayList<UserInfo> m_user=new ArrayList<UserInfo>();
    OnlineUserInfo parsedOnlineUserInfo;
    ImageAdapter m_adapter;
    private Runnable viewOrders;
    ProgressDialog m_ProgressDialog=null;
    Intent myIntent;
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        TextView tv=new TextView(this);
        Bundle bundle=new Bundle();
        bundle=this.getIntent().getExtras();
        String username=bundle.getString("username");
        String password=bundle.getString("password");
        tv.setText(username + " "+ password);
        setContentView(R.layout.onlineuserlist);
        this.m_adapter=new ImageAdapter(this, R.layout.onlineuserlistrow,m_user);
        setListAdapter(this.m_adapter);
        m_adapter.clear();
        ListView lv = getListView();
        lv.setTextFilterEnabled(true);

        lv.setOnItemClickListener(new OnItemClickListener()
        {


            public void onItemClick(AdapterView<?> parent, View view,int Position,long id)
            {
                Toast.makeText(OnlineUsersList.this,"hi",Toast.LENGTH_LONG).show();
                myIntent=new Intent(OnlineUsersList.this,SinglePantriesOnMap.class);
                startActivityForResult(myIntent, 0);
            }
        });
        viewOrders = new Runnable()
        {
            @Override
            public void run() 
            {
                try
                {
                    String url="http://www.lafoodbank.org/iphone/general-xml.aspx?mode=volunteer";
                    SAXParserFactory spf=SAXParserFactory.newInstance();
                    SAXParser sp=spf.newSAXParser();
                    XMLReader xr=sp.getXMLReader();
                    URL sourceURL= new URL(url);
                    OnlineUserXMLHandler onlineUserXmlHandler=new OnlineUserXMLHandler();
                    xr.setContentHandler(onlineUserXmlHandler);
                    xr.parse(new InputSource(sourceURL.openStream()));

                    parsedOnlineUserInfo=OnlineUserXMLHandler.getOnlineUserInfo();

                      getOnlineUsers();
                      try
                      {
                        Thread.sleep(1000);
                      }
                     catch (InterruptedException e)
                     {
                        e.printStackTrace();
                     }
                      runOnUiThread(returnRes);

                }
                catch(Exception e)
                {
                    System.out.println("====>Exception Raised in Parsing:"+ e);
                }

                 System.out.println("=============================================>>Total volunteers:"+parsedOnlineUserInfo.getName().size());
                runOnUiThread(returnRes);
            }

        };

        Thread thread =  new Thread(null, viewOrders, "MagentoBackground");
        thread.start();

          m_ProgressDialog = ProgressDialog.show(OnlineUsersList.this,    
             "Please Wait...!", "Retriving Volunteers...", true);





    }///on creat over
     private Runnable returnRes = new Runnable() 
     {

            @Override
            public void run()
            {
                if(m_user != null && m_user.size() > 0){
                    m_adapter.notifyDataSetChanged();

                    for(int i=0;i<m_user.size();i++)
                        m_adapter.add(m_user.get(i));
                }
                TextView total=(TextView)findViewById(R.id.totalVolunteers);
                total.setText("Total "+parsedOnlineUserInfo.getVId().size()+"Volunteers");       

                m_ProgressDialog.dismiss();
                m_adapter.notifyDataSetChanged();
            }
     };

    public void getOnlineUsers()
    {
        m_user=new ArrayList<UserInfo>();
        UserInfo user[]=null;
        user=new UserInfo[parsedOnlineUserInfo.getVId().size()];

        for(int i=0;i<parsedOnlineUserInfo.getVId().size();i++)
        {
            user[i]=new UserInfo();


            String vid=parsedOnlineUserInfo.getVId().get(i);
            String name=parsedOnlineUserInfo.getName().get(i);
            String organization=parsedOnlineUserInfo.getOrganization().get(i);
            String email=parsedOnlineUserInfo.getEmail().get(i);
            String longitude=parsedOnlineUserInfo.getLongitude().get(i);
            String latitude=parsedOnlineUserInfo.getLatitude().get(i);
            String address=parsedOnlineUserInfo.getAddress().get(i);
            String city=parsedOnlineUserInfo.getCity().get(i);
            String state=parsedOnlineUserInfo.getState().get(i);
            String otherState=parsedOnlineUserInfo.getOtherState().get(i);
            String zipCode=parsedOnlineUserInfo.getZipCode().get(i);
            String loginStatus=parsedOnlineUserInfo.getLoginStatus().get(i);
            String phone=parsedOnlineUserInfo.getPhone().get(i);
            String mobId=parsedOnlineUserInfo.getMobId().get(i);

            user[i].setVId(vid);
            user[i].setName(name);
            user[i].setOrganization(organization);
            user[i].setEmail(email);
            user[i].setLongitude(longitude);
            user[i].setLatitude(latitude);
            user[i].setAddress(address);
            user[i].setCity(city);
            user[i].setState(state);
            user[i].setOtherState(otherState);
            user[i].setZipCode(zipCode);
            user[i].setLoginStatus(loginStatus);
            user[i].setPhone(phone);
            user[i].setMobId(mobId);

            System.out.println("\n\n"+(i+1)+ " Volunteer");
            System.out.println("======================>USER INFO:ID"+user[i].getVId());
            System.out.println("======================>USER INFO:name"+user[i].getName());
            System.out.println("======================>USER INFO:organization"+user[i].getOrganization());
            System.out.println("======================>USER INFO:Email"+user[i].getEmail());
            System.out.println("======================>USER INFO:Longitude"+user[i].getLongitude());
            System.out.println("======================>USER INFO:Latitude"+user[i].getLatitude());
            System.out.println("======================>USER INFO:Addreess"+user[i].getAddress());
            System.out.println("======================>USER INFO:City"+user[i].getCity());
            System.out.println("======================>USER INFO:State"+user[i].getState());
            System.out.println("======================>USER INFO:OtherState"+user[i].getOtherState());
            System.out.println("======================>USER INFO:ZipCode"+user[i].getZipCode());
            System.out.println("======================>USER INFO:LOGIN STATUS"+user[i].getLoginStatus());
            System.out.println("======================>USER INFO:Phone"+user[i].getPhone());
            System.out.println("======================>USER INFO:MobileID"+user[i].getMobId());

            m_user.add(user[i]);
            //m_adapter.add(m_user.get(i));

        }

    }

    class ImageAdapter extends ArrayAdapter<UserInfo> 
    {
        private Arr开发者_如何学编程ayList<UserInfo> items;

        public ImageAdapter(Context context, int textViewResourceId,ArrayList<UserInfo> items) 
        {
            super(context, textViewResourceId, items);
            this.items = items;

        }

        public View getView(final int position, View convertView, ViewGroup parent) 
        {

            View v = convertView;
            if (v == null) 
            {
                try
                {
                LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = vi.inflate(R.layout.onlineuserlistrow, null);



                    }
                catch(Exception e)
                {
                    System.out.println("Excption Caught"+e);
                }
            }
            UserInfo user = items.get(position);


            if (user != null) 
            {
                TextView volunteerName = (TextView) v.findViewById(R.id.volunteerName);
                ImageView statusImg=(ImageView)v.findViewById(R.id.statusImg);

                if (volunteerName != null)
                {
                    volunteerName.setText(user.getName());
                }
                if(statusImg != null)
                {
                    int loginStatus=Integer.parseInt(user.getLoginStatus());
                    if(loginStatus==1)
                    {
                        statusImg.setImageResource(R.drawable.online);
                    }
                    else
                    {
                        statusImg.setImageResource(R.drawable.offline);
                    }
                }

            }


                return v;
        }

    }

}

If I PLACE SIMPLE ACTIVITY and remove MAPVIEW FROM XML FILE THEN MY CODE WORKS WELL...BUT WHEN I DECLARE ACTIVITY AS MAPACTIVITY and Place Mapview in XML File then EXCEPTION IS RAISED WHICH SAYS THAT COULD NOT FIND CLASS OF MAP ACTIVITY WHICH IS REFRENCED FROM onListItemClickListener()


I don't see it here, but you need a line like this in your android manifest file. It needs to be outside the activity tag and within the application tag.

<uses-library android:name="com.google.android.maps"/>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜