Java Code Examples for android.widget.ListView.setAdapter()

The following are Jave code examples for showing how to use setAdapter() of the android.widget.ListView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: LearnHangul   File: CharactersActivity.java   View Source Code Vote up 6 votes
private void setCharacterList(){

        ListView character_list = (ListView) findViewById(R.id.character_list);
        final ArrayAdapter<Character> adapter = new RowAdapter(this,characters);
        character_list.setAdapter(adapter);

        character_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                boolean isSelected = characters.get(i).isActive() ? false : true;
                characters.get(i).setActive(isSelected);
                adapter.notifyDataSetChanged();

            }
        });

    }
 
Example 2
Project: 2017.2-codigo   File: ContentConsumerActivity.java   View Source Code Vote up 6 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_content_consumer);
    ListView lv_pessoas = (ListView) findViewById(R.id.lv_Pessoas);
    ContentResolver cr = getContentResolver();
    //consulta na main thread, pode ser custoso, usar AsyncTask ou Loader
    Cursor c = cr.query(ContentProviderContract.CONTENT_LIST_URI, null, null, null, null);
    SimpleCursorAdapter adapter =
            new SimpleCursorAdapter(
                    this,
                    R.layout.itemlista,
                    c,
                    new String[] {ContentProviderContract.NOME},
                    new int[] {R.id.pNome},
                    0);
    lv_pessoas.setAdapter(adapter);
}
 
Example 3
Project: AttributionPresenter   File: ListActivity.java   View Source Code Vote up 6 votes
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_list);

    ListView list = (ListView) findViewById(R.id.list);
    list.setAdapter(AttributionPresenterCreator.create(
            this,
            new OnAttributionClickListener() {
                @Override
                public boolean onAttributionClick(Attribution attribution) {
                    Toast.makeText(getApplicationContext(), "Attribution click: " + attribution.getName(), Toast.LENGTH_SHORT).show();
                    return false;
                }
            },
            new OnLicenseClickListener() {
                @Override
                public boolean onLicenseClick(LicenseInfo licenseInfo) {
                    Toast.makeText(getApplicationContext(), "License click: " + licenseInfo.getName(), Toast.LENGTH_SHORT).show();
                    return true;
                }
            }).getAdapter());
}
 
Example 4
Project: react-native-udesk   File: UdeskOptionsAgentGroupActivity.java   View Source Code Vote up 6 votes
private void initView() {
    try {
        title = (TextView) findViewById(R.id.udesk_title);
        listView = (ListView) findViewById(R.id.udesk_options_listview);
        mTitlebar = (UdeskTitleBar) findViewById(R.id.udesktitlebar);
        adapter = new OptionsAgentGroupAdapter(this);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(this);
        title.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                backParentView();
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 5
Project: GitHub   File: ListViewBarChartActivity.java   View Source Code Vote up 6 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_listview_chart);
    
    ListView lv = (ListView) findViewById(R.id.listView1);

    ArrayList<BarData> list = new ArrayList<BarData>();

    // 20 items
    for (int i = 0; i < 20; i++) {
        list.add(generateData(i + 1));
    }

    ChartDataAdapter cda = new ChartDataAdapter(getApplicationContext(), list);
    lv.setAdapter(cda);
}
 
Example 6
Project: Bartout   File: DrinkBeverageActivity.java   View Source Code Vote up 6 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    android.content.Intent intent = getIntent();

    beverageName = intent.getStringExtra(beverageNameKey);
    beverageVolume = intent.getDoubleExtra(beverageVolumeKey, 0.0);
    beverageAlcoholicStrength = intent.getDoubleExtra(beverageAlcoholicKey, 0.0);

    bartour = Bartout.getInstance().getActiveBartour();
    users = bartour.getUsers();

    editTextBeverageName = (EditText) findViewById(R.id.editTextBeverageName);
    editTextBeverageVolume = (EditText) findViewById(R.id.editTextBeverageVolume);
    editTextAlcoholicStrength = (EditText) findViewById(R.id.editTextBeverageAlcoholicStrength);

    editTextBeverageName.setText(beverageName);
    editTextBeverageVolume.setText(Double.toString(beverageVolume));
    editTextAlcoholicStrength.setText(Double.toString(beverageAlcoholicStrength));

    listViewUsers = (ListView) findViewById(R.id.listViewDrinkUsers);

    UserBeverageAdapter userBeverageAdapter = new UserBeverageAdapter(this, users);
    listViewUsers.setAdapter(userBeverageAdapter);

}
 
Example 7
Project: yyox   File: OrderAttributeActivity.java   View Source Code Vote up 5 votes
@Override
protected void initWidgets() {
    super.initWidgets();
    mBackImg = (ImageView) findViewById(R.id.kf5_return_img);
    mBackImg.setOnClickListener(this);
    mListView = (ListView) findViewById(R.id.kf5_activity_order_attr_list_view);
    mUserFields = new ArrayList<>();
    mUserFieldAdapter = new UserFieldAdapter(mActivity, mUserFields);
    mListView.setAdapter(mUserFieldAdapter);
}
 
Example 8
Project: cat-is-a-dog   File: FollowersFragment.java   View Source Code Vote up 5 votes
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_followers, container, false);

    userId = CurrentUser.getInstance().getUserId();

    // Get follow requests where I am the followee and the request has been accepted
    followersDataSource = new FollowRequestDataSource(null, userId);
    followersDataSource.setOnlyShowAccepted(true);
    followersDataSource.addObserver(this);
    followers = followersDataSource.getSource();

    // Get follow requests that I have sent
    followRequestDataSource = new FollowRequestDataSource(userId, null);
    followRequestDataSource.addObserver(this);
    followRequests = followRequestDataSource.getSource();

    // Get all users
    userDataSource = new UserDataSource(userId);
    userDataSource.addObserver(this);
    users = userDataSource.getSource();

    followRequestsListView = (ListView) view.findViewById(R.id.followersListView);
    followersAdapter = new FollowersAdapter(getActivity(), followers, users, followRequests);
    followRequestsListView.setAdapter(followersAdapter);

    return view;
}
 
Example 9
Project: CustomWeight   File: MainActivity.java   View Source Code Vote up 5 votes
private void initView() {
    QuickIndexBar quickIndexBar = (QuickIndexBar) findViewById(R.id.quick_index_bar);
    listView = (ListView) findViewById(R.id.list_view);
    tvCurrentWord = (TextView) findViewById(R.id.tv_current_word);

    prepareData(); // 虚拟数据
    Collections.sort(friends); // 排序
    listView.setAdapter(new FriendAdapter(this, friends));

    quickIndexBar.setOnTouchLetterListener(new QuickIndexBar.OnTouchLetterListener() {
        @Override
        public void onTouchLetter(String letter) {
            //根据当前触摸的字母,去集合中找那个 item 的首字母和 letter 一样,然后将对应的item放到屏幕顶端
            for (int i = 0; i < friends.size(); i++) {
                String firstWord = friends.get(i).getPinYin().charAt(0) + "";
                if (letter.equals(firstWord)) {
                    // 说明找到了,那么应该讲当前的 item 放到屏幕顶端
                    listView.setSelection(i);
                    break;
                }
            }
            // 显示当前触摸的字母
            showCurrentWord(letter);
        }
    });

    // 通过缩小 tvCurrentWord 来隐藏
    ViewHelper.setScaleX(tvCurrentWord, 0f);
    ViewHelper.setScaleY(tvCurrentWord, 0f);
}
 
Example 10
Project: Tribe   File: NearbyListFragment.java   View Source Code Vote up 5 votes
private void initPullToRefreshListView() {
    mData = new ArrayList<>();
    mAdapter = new NearbyListAdapter(getContext(), mData, mLongitude, mLatitude, getActivity());
    ListView listView = mPullToRefreshNearbylist.getRefreshableView();
    listView.setAdapter(mAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long id) {
            Intent intent = new Intent(getContext(), PersonalHomeActivity.class);
            intent.putExtra("other_by_id",mData.get(i-1).getUserid());
            startActivity(intent);
        }
    });

}
 
Example 11
Project: LucaHome-AndroidApplication   File: DialogController.java   View Source Code Vote up 5 votes
public void DisplaySocketListViewDialog(SerializableList<WirelessSocket> wirelessSocketList) {
    final Dialog dialog = createDialog();
    dialog.setContentView(R.layout.dialog_listview);

    TextView titleView = dialog.findViewById(R.id.dialog_title_text_view);
    titleView.setText("Wireless Sockets");

    com.rey.material.widget.Button closeButton = dialog.findViewById(R.id.dialog_button_close);
    closeButton.setOnClickListener(v -> dialog.dismiss());

    ListView listView = dialog.findViewById(R.id.dialog_list_view);
    listView.setAdapter(new SocketListViewAdapter(_context, wirelessSocketList, dialog));

    displayDialog(dialog);
}
 
Example 12
Project: yjPlay   File: BelowView.java   View Source Code Vote up 5 votes
/**
 * Instantiates a new Below view.
 *
 * @param c        the c
 * @param listName the list name
 */
public BelowView(@NonNull Context c, @Nullable List<String> listName) {
    this.convertView = View.inflate(c, R.layout.simple_exo_belowview, null);
    listView = (ListView) convertView.findViewById(R.id.list_item);
    if (listName == null) {
        listName = Arrays.asList(c.getResources().getStringArray(R.array.exo_video_switch_text));
    }
    adapter = new SwitchAdapter(c, listName);
   listView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
    listView.setAdapter(adapter);
}
 
Example 13
Project: chromium-for-android-56-debug-video   File: PassphraseTypeDialogFragment.java   View Source Code Vote up 5 votes
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View v = inflater.inflate(R.layout.sync_passphrase_types, null);

    // Configure the passphrase type list
    ListView list = (ListView) v.findViewById(R.id.passphrase_types);
    Adapter adapter = createAdapter(getCurrentTypeFromArguments());
    list.setAdapter(adapter);
    list.setId(R.id.passphrase_type_list);
    list.setOnItemClickListener(this);
    list.setDividerHeight(0);
    PassphraseType currentType = getCurrentTypeFromArguments();
    list.setSelection(adapter.getPositionForType(currentType));

    // Configure the hint to reset the passphrase settings
    // Only show this hint if encryption has been set to use sync passphrase
    if (currentType == PassphraseType.CUSTOM_PASSPHRASE) {
        TextView instructionsView = (TextView) v.findViewById(R.id.reset_sync_text);
        instructionsView.setVisibility(View.VISIBLE);
        instructionsView.setMovementMethod(LinkMovementMethod.getInstance());
        instructionsView.setText(getResetText());
    }

    // Create and return the dialog
    return new AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme)
            .setNegativeButton(R.string.cancel, this)
            .setTitle(R.string.sync_passphrase_type_title)
            .setView(v)
            .create();
}
 
Example 14
Project: HappyWeather   File: ChooseAreaFragment.java   View Source Code Vote up 5 votes
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.choose_area, container, false);
    titleText = (TextView) view.findViewById(R.id.title_text);
    backButton = (Button) view.findViewById(R.id.back_button);
    listView = (ListView) view.findViewById(R.id.list_view);
    adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_list_item_1, dataList);
    view.setBackgroundColor(0xffffffff);
    listView.setAdapter(adapter);
    return view;
}
 
Example 15
Project: bluewatcher   File: NotificationsActivity.java   View Source Code Vote up 5 votes
private void initializeNotificationsList() {
	listView = (ListView) findViewById(R.id.list_notifications_view);

	ArrayAdapter<ConfigurationOption> adapter = new ArrayAdapter<ConfigurationOption>(this.getBaseContext(), android.R.layout.simple_list_item_1);
	adapter.add(new ConfigurationOption(IncomingCallConfigActivity.class, getString(R.string.incoming_call_config)));
	adapter.add(new ConfigurationOption(WhatsappConfigActivity.class, getString(R.string.whatsapp_config)));
	adapter.add(new ConfigurationOption(GenericNotificationsActivity.class, getString(R.string.custom_notification_config)));
	listView.setAdapter(adapter);
	listView.setOnItemClickListener(new OnConfigurationOptionSelected(this, listView));
}
 
Example 16
Project: android-apps   File: OSChinaProjectFragment.java   View Source Code Vote up 4 votes
@Override
@Nullable
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  View view = inflater.inflate(R.layout.fragment_oschina, container, false);

  refreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.refresh_layout);
  listView = (ListView) view.findViewById(R.id.list_view);
  adapter = new MyBaseAdapter<Map<String, Object>>(getActivity(), data) {
    List<Integer> positions = new ArrayList<>();

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      ViewHolder holder = ViewHolder.get(context, convertView, parent, R.layout.list_view_item_osc, position);
      Map<String, Object> map = data.get(position);
      holder.setText(R.id.title, map.get("title").toString())
          .setText(R.id.desc, map.get("desc").toString())
          .setText(R.id.replyCount, map.get("replyCount").toString())
          .setText(R.id.time, map.get("time").toString());
      holder.setNetImage(R.id.avatar, map.get("avatar").toString());
      holder.getView(R.id.readFirstImg).setVisibility(View.GONE);
      if (map.get("readFirstImg") != null) {
        positions.add(holder.getPosition());
      } else {
        positions.remove((Integer) holder.getPosition());
      }
      if (positions.contains(holder.getPosition())) {
        holder.setNetImage(R.id.readFirstImg, map.get("readFirstImg").toString());
        holder.getView(R.id.readFirstImg).setVisibility(View.VISIBLE);
      }
      return holder.getConvertView();
    }
  };
  listView.setAdapter(adapter);
  loadMoreFooter = new LoadMoreFooter(getActivity(), listView, this);

  refreshLayout.setOnRefreshListener(this);
  listView.setOnItemClickListener(this);

  refreshLayout.setRefreshing(true);
  return view;
}
 
Example 17
Project: apps_small   File: MainActivity.java   View Source Code Vote up 4 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Defining the list view that I want by id.
    theList = (ListView) findViewById(R.id.theList);

    // Defining an array of names.
    myList = new ArrayList();

    // Defining the array of lattitude.
    latList = new ArrayList();

    // Defining the array of longitude.
    longList = new ArrayList();

    // Only want to do this once....
    if (myList.size() < 1) {

        // Adding names to the array list.
        myList.add("Alaska");
        latList.add("64");
        longList.add("-147");

        Log.i("WJH", "Adding Alaska to blank list.");

    }

    // Defining an adapter, to adapt my array list to the correct format.
    addaptedAray = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, myList);

    // Using the adapter to adapt my array list to the defined list view that I declared already.
    theList.setAdapter(addaptedAray);

    // Setting up a listener to "listen" for me to click on something in the list.
    theList.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        // Overriding the generic code that Android uses for list views to do something specific.
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int z, long l) {

            // Converting the integer of "z" to a string with the name of the item clicked in the list.
            String a = (String) myList.get(z);
            String b = (String) latList.get(z);
            String c = (String) longList.get(z);

            // Logging that I tapped said item in the list.
            Log.i("WJH", a + b + c);


            Intent myIntent = new Intent(getApplicationContext(), MapsActivity.class);
            myIntent.putExtra("namePlace", a);
            myIntent.putExtra("latPlace", b);
            myIntent.putExtra("longPlace", c);
            startActivityForResult(myIntent, 1);

        }
    });
}
 
Example 18
Project: R-a-dio-Amazing-Android-App   File: ActivityMain.java   View Source Code Vote up 4 votes
public void setSongList(String json) throws JSONException{
    View requestView = viewPager.findViewById(R.id.requests_page);
    TextView searchMsg = (TextView) requestView.findViewById(R.id.searchMsg);
    ListView songListView = (ListView) requestView.findViewById(R.id.songListView);
    Integer curPage, lastPage;

    try {
        JSONObject searchObject = new JSONObject(json);
        JSONArray songs = new JSONArray(searchObject.getString("data"));
        ArrayList<Song> songList = new ArrayList<>();
        curPage = searchObject.getInt("current_page");
        lastPage = searchObject.getInt("last_page");

        for (int i = 0; i < songs.length(); i++){
            JSONObject songObject = songs.getJSONObject(i);

            if(songObject != null){
                String artist = songObject.getString("artist");
                String title = songObject.getString("title");
                Integer songID = songObject.getInt("id");
                boolean requestable = songObject.getBoolean("requestable");
                Song song = new Song(artist, title, songID, requestable);

                songList.add(song);
            }
        }

        if(songs.length() == 0) {
            searchMsg.setVisibility(View.VISIBLE);
            searchMsg.setText("No songs found for query.");
        } else {
            searchMsg.setVisibility(View.INVISIBLE);
        }

        if(searchFooter == null || songListView.getFooterViewsCount() == 0) {
            createSearchFooter(curPage, lastPage);
            songListView.addFooterView(searchFooter);
        }
        else {
            createSearchFooter(curPage, lastPage);
        }
        SongAdapter sAdapt = new SongAdapter(this, R.layout.request_cell, songList);
        songListView.setAdapter(sAdapt);
    }
    catch(JSONException ex){
        searchMsg.setVisibility(View.VISIBLE);
        searchMsg.setText("An error occurred while retrieving songs. Please try again.");
    }
}
 
Example 19
Project: sa-android   File: LibraryBookDetailsActivity.java   View Source Code Vote up 4 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_library_book_details);

    // Create adapter
    ListView listView = (ListView) findViewById(R.id.listView);
    mAdapter = new DetailsAdapter(this, R.layout.list_item_book_details, mInventory);
    listView.setAdapter(mAdapter);
    final ProgressBar pbBusy = (ProgressBar) findViewById(R.id.pbBusy);

    // Show ProgressBar
    pbBusy.setVisibility(View.VISIBLE);

    String book_id = getIntent().getStringExtra("book_id");
    String book_title = getIntent().getStringExtra("book_title");
    String book_author = getIntent().getStringExtra("book_author");
    String book_publisher = getIntent().getStringExtra("book_publisher");
    String book_year = getIntent().getStringExtra("book_year");
    String book_acquisition_number = getIntent().getStringExtra("book_acquisition_number");
    String book_inventory = getIntent().getStringExtra("book_inventory");
    String book_available = getIntent().getStringExtra("book_available");

    LibraryModels.details(book_id, new ModelListener<List<BookInventory>>() {
        @Override
        public void onData(List<BookInventory> result, String message) {
            // Hide ProgressBar
            pbBusy.setVisibility(View.INVISIBLE);

            if (result == null) {
                Toast.makeText(LibraryBookDetailsActivity.this, message, Toast.LENGTH_SHORT).show();
                return;
            }
            mInventory.clear();
            mInventory.addAll(result);
            mAdapter.notifyDataSetChanged();
        }
    });

    TextView lblTitle = (TextView) findViewById(R.id.lblTitle);
    TextView lblAuthor = (TextView) findViewById(R.id.lblAuthor);
    TextView lblInventory = (TextView) findViewById(R.id.lblInventory);
    TextView lblAvailable = (TextView) findViewById(R.id.lblAvailable);
    TextView lblYear = (TextView) findViewById(R.id.lblYear);
    TextView lblPublisher = (TextView) findViewById(R.id.lblPublisher);
    TextView lblAcqNum = (TextView) findViewById(R.id.lblAcqNum);

    if (book_title != null) lblTitle.setText(book_title);
    if (book_author != null) lblAuthor.setText(book_author);
    String storeNum = "馆藏:" + book_inventory;
    String availableNum = "可借:" + book_available;
    if (book_inventory != null) lblInventory.setText(storeNum);
    if (book_available != null) lblAvailable.setText(availableNum);
    if (book_year != null) lblYear.setText(book_year);
    if (book_publisher != null) lblPublisher.setText(book_publisher);

    if (book_acquisition_number != null) lblAcqNum.setText(book_acquisition_number);
}
 
Example 20
Project: Android-2017   File: CustomItemActivity.java   View Source Code Vote up 4 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_custom_item);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // recuperamos la listview
    ListView lv = (ListView) findViewById(R.id.customItemsListView);

    // creamos unos elementos de pruebas
    List elementos = new ArrayList<Elemento>();

    elementos.add(new Elemento(R.mipmap.ic_android, "Androide"));
    elementos.add(new Elemento(R.mipmap.ic_baby, "Baby"));
    elementos.add(new Elemento(R.mipmap.ic_film, "Film"));

    // creamos el adapter y lo asignamos a la lista

    lv.setAdapter(new CustomAdapter(this, elementos));

}