如何从 ArrayAdapter 上的 ListView 获取索引和字符串 class

how to get Index and String from ListView on ArrayAdapter class

我正在创建网络服务应用程序。它有 ArrayAdapter class 将 Web 数据呈现给 Listview。我想获取所选 Listview 项的索引并将索引值发送到下一个 activity 以执行其他任务。但我无法从 ListView 获取索引。 ListView id 是默认的 Android API id

我几乎使用了 setOnItemSelectedListenersetOnClickListener OnItemSelectedListener 但没有用

 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);        
        setContentView(R.layout.activity_main);     

        initView();   
    }

    private void initView() {
        // show progress dialog
        dialog = ProgressDialog.show(this, "", "Loading...");

        String url = "xxxxxxxx";
        // json class doing background data processing  
        FetchDataTask task = new FetchDataTask(this);
        task.execute(url);
    }

    @Override
    public void onFetchComplete(List<Application> data) {
        // dismiss the progress dialog
        if(dialog != null)  dialog.dismiss();
        // create new adapter
     ApplicationAdapter adapter = new ApplicationAdapter(this, data);
        // set the adapter to list
        lv.setAdapter(adapter);        

         }

这是 ArrayAdapter class

public class ApplicationAdapter extends ArrayAdapter<Application>  implements OnItemClickListener{
    private List<Application> items;
    ListView listview;
    public ApplicationAdapter(Context context, List<Application> items) {
        super(context, R.layout.app_custom_list, items);
        this.items = items;

        MainActivity.lv.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() 
        {
            public void onItemSelected(AdapterView<?> parentView, View childView, int position, long id) 
            {
                String text = ((TextView)childView.getTag()).toString();
             Log.d("index",text);
            }
            public void onNothingSelected(AdapterView<?> parentView) 
            {
            }
        });
    }

    @Override
    public int getCount() {
        return items.size();
    }



    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;

        if(v == null) {
            LayoutInflater li = LayoutInflater.from(getContext());
            v = li.inflate(R.layout.app_custom_list, null);            
        }

        Application app = items.get(position);

        if(app != null) {
            ImageView icon = (ImageView)v.findViewById(R.id.appIcon);



                for(int i=1; i<=5; i++) {
                    ImageView iv = new ImageView(getContext());

                    if(i <= app.getRating()) {
                        iv.setImageDrawable(getContext().getResources().getDrawable(R.drawable.start_checked));
                    }
                    else {                
                        iv.setImageDrawable(getContext().getResources().getDrawable(R.drawable.start_unchecked));
                    }

                    ratingCntr.addView(iv);
                }
            }
        }

        return v;
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {
        String[] lv_arr = null;
        // TODO Auto-generated method stub
        String itemname = lv_arr[position];
        Log.d("string from ListView",itemname);


    }
}

请帮助我获取 ListView 的所选项目的索引。如果有人可以建议我应该使用什么,我将不胜感激

提前致谢

protected void onCreate(Bundle savedInstanceState) {的底部添加

    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

      //get position index of item here. 

       String indexid = String.valueOf(position);  

       //and do whatever afterwards.                              


                        });

                    }

并删除适配器中的 public void onItemClick(AdapterView<?> parent, View view, int position, .......