Android 从listView片段打开活动

Android 从listView片段打开活动,android,listview,android-fragments,Android,Listview,Android Fragments,这是我的第一个应用程序。我有一个由列表视图填充的片段,它从Web服务获取数据。我希望能够单击列表视图项并打开新活动。虽然每个项目都是相同的活动,但我将传递一个不同的变量。我看过很多其他关于这个的帖子。他们都不为我工作。请帮忙,谢谢 public class TicketFragment extends Fragment { ListView tv; ProgressDialog mProgressDialog; public TicketFragment(){}

这是我的第一个应用程序。我有一个由列表视图填充的片段,它从Web服务获取数据。我希望能够单击列表视图项并打开新活动。虽然每个项目都是相同的活动,但我将传递一个不同的变量。我看过很多其他关于这个的帖子。他们都不为我工作。请帮忙,谢谢

public class TicketFragment extends Fragment {
    ListView tv;
    ProgressDialog mProgressDialog;

    public TicketFragment(){}
    private String TAG ="Vik";

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_ticket, container, false);
        tv =(ListView)rootView.findViewById(R.id.listView1);

        AsyncCallWS task = new AsyncCallWS();
        task.execute();

        return rootView;
    }

    private class AsyncCallWS extends AsyncTask<Void, Void, Void> {

        @Override
        protected Void doInBackground(Void... params) {
            location();
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
           // Log.i(TAG, "onPostExecute");

        }

        @Override
        protected void onPreExecute() {
           // Log.i(TAG, "onPreExecute");

        }

        @Override
        protected void onProgressUpdate(Void... values) {
            //Log.i(TAG, "onProgressUpdate");
            mProgressDialog.setMessage("Loading locations.....");
        }

    }     

    public void location() {
        String SOAP_ACTION = "http://example.com/getlocations";
        String METHOD_NAME = "getlocations";
        String NAMESPACE = "http://example.com/";
        String URL = "http://localhost/Example/Service.asmx";   

        try { 
            SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
            //Request.addProperty("get locations", "3");

            SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);
            soapEnvelope.dotNet = true;
            soapEnvelope.setOutputSoapObject(Request);

            HttpTransportSE transport= new HttpTransportSE(URL);

            transport.call(SOAP_ACTION, soapEnvelope);

            SoapObject response = (SoapObject)soapEnvelope.getResponse();

            System.out.println(response);
            int intPropertyCount = response.getPropertyCount();
            String[] locations= new String[intPropertyCount];

            for (int i = 0; i < intPropertyCount; i++) {               
                locations[i] = response.getPropertyAsString(i).toString();
            }

            final ArrayAdapter<String> adapter =
            new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, locations);

            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    // This code will always run on the UI thread, therefore is safe to modify UI elements.
                    tv.setAdapter(adapter);
                }
            });

        }
        catch(Exception ex) {
            Log.e(TAG, "Error: " + ex.getMessage());
        }

    }
}
公共类TicketFragment扩展片段{
列表视图电视;
进程对话框;
public TicketFragment(){}
私有字符串TAG=“Vik”;
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
视图根视图=充气机。充气(R.layout.fragment\u票据,容器,假);
tv=(ListView)rootView.findViewById(R.id.listView1);
AsyncCallWS任务=新建AsyncCallWS();
task.execute();
返回rootView;
}
私有类AsyncCallWS扩展了AsyncTask{
@凌驾
受保护的Void doInBackground(Void…参数){
位置();
返回null;
}
@凌驾
受保护的void onPostExecute(void结果){
//Log.i(标记“onPostExecute”);
}
@凌驾
受保护的void onPreExecute(){
//Log.i(标记“onPreExecute”);
}
@凌驾
受保护的void onProgressUpdate(void…值){
//Log.i(标记“onProgressUpdate”);
setMessage(“加载位置…”);
}
}     
公共位置(){
字符串SOAP_ACTION=”http://example.com/getlocations";
字符串方法\u NAME=“getlocations”;
字符串命名空间=”http://example.com/";
字符串URL=”http://localhost/Example/Service.asmx";   
试试{
SoapObject请求=新的SoapObject(名称空间、方法名称);
//请求。添加属性(“获取位置”、“3”);
SoapSerializationEnvelope soapEnvelope=新的SoapSerializationEnvelope(
第11版);
soapEnvelope.dotNet=true;
setOutputSoapObject(请求);
HttpTransportSE传输=新的HttpTransportSE(URL);
调用(SOAP\u操作,soapEnvelope);
SoapObject响应=(SoapObject)soapEnvelope.getResponse();
System.out.println(响应);
int intPropertyCount=response.getPropertyCount();
字符串[]位置=新字符串[intPropertyCount];
对于(inti=0;i
您需要在列表视图中添加一个单击侦听器:

tv.setOnItemClickListener(new OnItemClickListener() {

    public void onItemClick(AdapterView<?> adapter, View v, int position, long id) {
        Intent intent = new Intent(getActivity(), DestinationActivity.class);
        // add data to the intent...
        startActivity(intent);
}
tv.setOnItemClickListener(新的OnItemClickListener(){
公共控件单击(适配器视图适配器,视图v,内部位置,长id){
Intent Intent=new Intent(getActivity(),DestinationActivity.class);
//向目标添加数据。。。
星触觉(意向);
}

到底什么不起作用?我拥有的正在起作用。我不知道如何使列表视图可单击并打开新活动