title: How To pre-select value in Listview SingleChoice?
body: <p>How to Preselect value in ListView Single Choice? Actually I am creating app where user have to select his work type like farmer etc.</p>
  
  <p>And in my database user selected farmer now through this listview I am giving him to choice to change is type so that's why I have to show first what he selected first.</p>
  
  <p>Here is my code.</p>
  
  <pre><code>public class UserTypeSettings extends AppCompatActivity {
  
  private List&lt;UserTypePrivacySettings&gt; userTypePrivacySettingsList;
  private ListView userTypeListView;
  private int listpos;
  
  
  public int getListpos() {
      return listpos;
  }
  
  public void setListpos(int listpos) {
      this.listpos = listpos;
  }
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_user_type_settings);
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
  
      setActionbar();
      initViews();
  
  
  }
  
  private void initViews() {
      userTypeListView = (ListView) findViewById(R.id.userTypeListView);
      userTypeListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
      userTypePrivacySettingsList = new Parse(UserTypeSettings.this).parseUserType();
  
      userTypeListView.setAdapter(new SingleChoiceArrayadapter(this, userTypePrivacySettingsList) {
          @Override
          public View getView(int position, View convertView, ViewGroup parent) {
              setListpos(position);
  
              return super.getView(position, convertView, parent);
          }
      });
  
     userTypeListView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
          }
  
          @Override
          public void onNothingSelected(AdapterView&lt;?&gt; parent) {
  
          }
  
      });
      userTypeListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
              Log.e("check user stype", userTypePrivacySettingsList.get(position).getUser_type());
          }
  
      });
  }}
  </code></pre>
  
  <p>Here is my adapter class</p>
  
  <pre><code>public class SingleChoiceArrayadapter extends ArrayAdapter&lt;UserTypePrivacySettings&gt; {
      public SingleChoiceArrayadapter(Context context, List&lt;UserTypePrivacySettings&gt; usertypes) {
          super(context, 0, usertypes);
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          if (convertView == null) {
              convertView = LayoutInflater.from(getContext()).inflate(android.R.layout.simple_list_item_single_choice, parent, false);
          }
  
  
          UserTypePrivacySettings user = getItem(position);
          final CheckedTextView textView = (CheckedTextView) super.getView(position, convertView, parent);
          textView.setText(user.getUser_type());
          textView.setTextColor(getResources().getColor(R.color.kisanColorGreen));
  
  
  
          return convertView;
      }
  
      @Override
      public long getItemId(int position) {
          return getItem(position).getUser_type().hashCode();
      }
  
      @Override
      public boolean hasStableIds() {
          return true;
      }
  
  
  }
  </code></pre>