2 ssummeraw ssummeraw 于 2013.08.08 17:06 提问

处理 ListView 中一个 list item的问题

我创建了一个自定义的Listview。List中的每一个item都有一个 imageView和两个TextView。
代码是:

public class PersonalList extends ListActivity{

 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String[] name= new String[] { "Mary", "Frank",
            "John" };
    String[] surname = new String[] { "Ballak", "Doe",
            "Strip"" };
    setContentView(R.layout.member_list);

    MySimpleArrayAdapter adapter = new MySimpleArrayAdapter(this, name, surname);
    setListAdapter(adapter);
}
 protected void onListItemClick(ListView l, View v, int position, long id) {
    String name = (String) getListAdapter().getItem(position);
    Toast.makeText(this, "selected item: "+name, Toast.LENGTH_LONG).show();     
  }
 }

还有MySimpleArrayAdapter是:

public class MySimpleArrayAdapter extends ArrayAdapter<String> {
      private final Context context;
      private final String[] name;
      private final String[] surname;

      public MySimpleArrayAdapter(Context context, String[] name, String[] surname)
      {
          super(context, R.layout.list_row, name);
          this.context = context;
          this.name= name;
          this.surname = surname;
      }

      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.rowlayout, parent, false);
        TextView nameView= (TextView) rowView.findViewById(R.id.label);
        TextView surnameView= (TextView) rowView.findViewById(R.id.label1);
        ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
        nameView.setText(name[position]);
        surnameView.setText(surname[position]);

        return rowView;
      }
  } 

从onListItemClick中调用下面的代码:

 Toast.makeText(this, "selected item: "+name, Toast.LENGTH_LONG).show();

我在toast 中获取第一个item的信息:

"selected item: Mary"

如何才能获得接下来以后的信息呢?

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!