사용자 지정 ListView를 만들었습니다. 목록의 각 항목에는 하나의 imageView와 두 개의 TextView가 있습니다.ListView의 목록 항목 관리
코드는 다음과 같습니다
Toast.makeText(this, "selected item: "+name, Toast.LENGTH_LONG).show();
내가 첫 번째 항목 토스트의 메시지를 얻을 : onListItemClick
에서 다음 코드를 호출
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;
}
}
:
는 MySimpleArrayAdapter는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();
}
}
입니다 이렇게 :
"selected item: Mary"
다음 결과를 얻으려면 어떻게해야합니까?
"selected item: Mary Ballak"
: LL처럼
Activity
뭔가의 구성원으로 배열을 저장 ain Guy [어댑터와 효율성에 대해 논의] (http://www.google.com/events/io/2009/sessions/TurboChargeUiAndroidFast.html) 일부 제안 팁과 ArrayAdapter의 고유 한 메소드를 사용하지 않기 때문에 BaseAdapter를 확장합니다. – Sam