Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to use ArrayAdapter class in android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 258
    Comment on it

    In the below example, first I have created ArrayAdapter class and then extend ListActivity. In next line I have store ListItems in String then I have setListAdapter. ”ArrayAdapter class can handle a list item as input, By using this class we are managing the items in the list”. You can see below program it will clearly describe you how to use ArrayAdapter in android.

     

    public class ArrayAdapter extends ListActivity {
       TextView selection;
       String[] items = { "one", "two ", "three", "four"};
       @Override
       public void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.activity_main);
    setListAdapter(new ArrayAdapter<String>(
          this,
          android.R.layout.simple_expandable_list_item_1,
          items));
    selection=(TextView)findViewById(R.id.selection); 
       }
    
    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    String text = " position:" + position + "  " + items[position];
    selection.setText(text);
    }
          
    }

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: