アイテムを含むリストビューがあります。各アイテムは、editText とその他のコンポーネントを含む linearLayout です。
ここで、イベントを editText に関連付けたいと思います。特に、ユーザーによって変更されたかどうかを知る必要があります。
私の考えは、リストビューの customAdapter を作成し、そこでイベントを処理することです...続行する正しい方法ですか?
アイテムを含むリストビューがあります。各アイテムは、editText とその他のコンポーネントを含む linearLayout です。
ここで、イベントを editText に関連付けたいと思います。特に、ユーザーによって変更されたかどうかを知る必要があります。
私の考えは、リストビューの customAdapter を作成し、そこでイベントを処理することです...続行する正しい方法ですか?
はい、カスタム アダプターを作成するのがよい方法です。
アダプター内getView()でイベントを処理し、それを使用してそれに応じてイベントに応答できます。
この素晴らしいチュートリアルのサンプル コードは次のとおりです。
public class MyListAdapter extends ArrayAdapter{
private int resource;
private LayoutInflater inflater;
private Context context;
public MyListAdapter ( Context ctx, int resourceId, Listobjects) {
super( ctx, resourceId, objects );
resource = resourceId;
inflater = LayoutInflater.from( ctx );
context=ctx;
}
@Override
public View getView ( int position, View convertView, ViewGroup parent ) {
/* create a new view of my layout and inflate it in the row */
convertView = ( RelativeLayout ) inflater.inflate( resource, null );
/* Extract the city's object to show */
City city = getItem( position );
/* Take the TextView from layout and set the city's name */
TextView txtName = (TextView) convertView.findViewById(R.id.cityName);
txtName.setText(city.getName());
/* Take the TextView from layout and set the city's wiki link */
TextView txtWiki = (TextView) convertView.findViewById(R.id.cityLinkWiki);
txtWiki.setText(city.getUrlWiki());
/* Take the ImageView from layout and set the city's image */
ImageView imageCity = (ImageView) convertView.findViewById(R.id.ImageCity);
String uri = "drawable/" + city.getImage();
int imageResource = context.getResources().getIdentifier(uri, null, context.getPackageName());
Drawable image = context.getResources().getDrawable(imageResource);
imageCity.setImageDrawable(image);
return convertView;
}
}