-1

I have a fragment with a AsyncTask in which I do a parsing Json. To put every element in a list I use a SimpleAdapter. In my item list I have a button. Of course, if I want click on the button I need to create a getView. Well not works. This is the SimpleAdapter part inside the AsyncTask

ListAdapter adapter = new SimpleAdapter(getActivity(), list, R.layout.list_rom_item, 
                  new String[] { TAG_NAME, TAG_SURNAME }, new int[] { R.id.name, R.id.surname}); 

Now, after that, I tried to put this:

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

                      Button b=(Button)v.findViewById(R.id.mytask);
                      b.setOnClickListener(new OnClickListener() {

                         @Override
                         public void onClick(View arg0) {
                             // TODO Auto-generated method stub
                             Toast.makeText(MainActivity.this,"save",Toast.LENGTH_SHORT).show();
                         }
                     });
                     return v;
                 }

I get an error in @Override like: The annotation @Override is disallowed for this location and then of course in getView() syntax.. I don't know why. I tried also to clean the project but nothing. Is there any other solution maybe? Thanks.

Carsten Løvbo Andersen
  • 26,637
  • 10
  • 47
  • 77
Atlas91
  • 5,754
  • 17
  • 69
  • 141
  • where exactly have you placed this getView() method? Can you post bigger part of your code? – user2203031 Nov 07 '14 at 19:18
  • argh it's a long code..mmh in `onPostExecute` method however.. just before the adapter i do the `HashMap map = new HashMap();` then the adapter and then the getView. Just after the adapter statement. – Atlas91 Nov 07 '14 at 19:21

1 Answers1

1

You should override getView() method when instantiating your adapter. After that, you will not be able to do that.

Try this way:

ListAdapter adapter = new SimpleAdapter(getActivity(), list, R.layout.list_rom_item, 
                  new String[] { TAG_NAME, TAG_SURNAME }, new int[] { R.id.name, R.id.surname}) {
    @Override
    public View getView (int position, View convertView, ViewGroup parent) {
        ...
        return v;
    }
}
user2203031
  • 402
  • 3
  • 14