Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 当项目为复杂布局时,向listview项目添加事件_Android - Fatal编程技术网

Android 当项目为复杂布局时,向listview项目添加事件

Android 当项目为复杂布局时,向listview项目添加事件,android,Android,我有一个包含项目的列表视图,每个项目都是一个带有editText和其他组件的线性布局 现在,我想将一个事件与editText关联,特别是我需要知道它是否被用户修改 我的想法是为listview创建一个customAdapter,然后在那里处理事件……这是正确的方法吗?是的,创建一个自定义适配器是正确的方法 您可以在适配器的getView()内处理事件,然后使用它相应地响应事件 以下是来自以下内容的示例代码: public class MyListAdapter extends ArrayAda

我有一个包含项目的列表视图,每个项目都是一个带有editText和其他组件的线性布局

现在,我想将一个事件与editText关联,特别是我需要知道它是否被用户修改


我的想法是为listview创建一个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;
      }
}