How do you get the values from ArrayAdapter?



  • Created an adapter, inherited it from ArrayAdapter. There is a list of List View, which fills the user in manually. The task is to remove the list on the screen after the new inclusion of the annex (if the list has previously been drawn up). Adapter:

         public class MyAdapter extends ArrayAdapter<Info> {
    
     ArrayList&lt;Info&gt; nameInfo = new ArrayList&lt;Info&gt;();
    
     public MyAdapter(Context context, ArrayList&lt;Info&gt; nameInfo) {
     super(context, 0, nameInfo);
    
    
     }
    
     @Override
     public View getView(int position, View convertView, ViewGroup parent) {
    
     Info data = getItem(position);
     if (convertView == null) {
        convertView =                                                                
    LayoutInflater.from(getContext()).inflate(R.layout.row, parent, false);
    }
    
    TextView column1 = (TextView) convertView.findViewById(R.id.col1);
    TextView column2 = (TextView) convertView.findViewById(R.id.col2);
    
    
    column1.setText(data.par1);
    column2.setText(data.par2);
    
    
    return convertView;
    }
    

    }

    `

    Here's a list and an adapter to the Main activate:

        MyAdapter = new MyAdapter(this, nameInfo);

    ListView lvMain = (ListView) findViewById(R.id.lvMain);
    lvMain.setAdapter(MyAdapter);
    



  • Determine the method for receiving the Web. getItems:

    public class MyAdapter extends ArrayAdapter<Info> {
    

    List<Info> nameInfo = new ArrayList<Info>();

    public MyAdapter(Context context, List<Info> nameInfo) {
    super(context, 0, nameInfo);

    }

    public List<Info> getItems(){
    return nameInfo ;
    }
    [...]
    }

    So how am I https://ru.stackoverflow.com/questions/476125/%D0%A1%D0%BE%D1%85%D1%80%D0%B0%D0%BD%D0%B5%D0%BD%D0%B8%D0%B5-%D1%8D%D0%BB%D0%B5%D0%BC%D0%B5%D0%BD%D1%82%D0%BE%D0%B2-listview-%D0%BF%D0%BE%D1%81%D0%BB%D0%B5-%D0%BF%D0%B5%D1%80%D0%B5%D0%B7%D0%B0%D0%B3%D1%80%D1%83%D0%B7%D0%BA%D0%B8-%D0%BF%D1%80%D0%B8%D0%BB%D0%BE%D0%B6%D0%B5%D0%BD%D0%B8%D1%8F Your question was described:

    public void onSaveInstanceState(Bundle savedState) {

    super.onSaveInstanceState(savedState);
    
    // здесь берём данные из адаптера
    List&lt;Info&gt; items = mAdapter.getItems();
    savedState.putParcelableArrayList("my_data", items);
    

    }

    It's still in your class. Info implementation https://developer.android.com/intl/ru/reference/android/os/Parcelable.html interface.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2