List of usage examples for android.widget ListView setAdapter
@Override public void setAdapter(ListAdapter adapter)
From source file:com.cs411.trackallthethings.ItemsOnLoan.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.itemsonloan); // bind the ArrayList of Item Objects to the Array Adapter // and then bind the Array Adapter to the ListView ListView itemsOnLoanFeed = (ListView) findViewById(R.id.itemsonloanfeed); itemsOnLoanAdapter = new ArrayAdapter<Item>(this, R.layout.item, itemsOnLoan); itemsOnLoanFeed.setAdapter(itemsOnLoanAdapter); // fire up an AsyncTask to get the user's items //show the loading dialog loading = ProgressDialog.show(ItemsOnLoan.this, "", "Getting your items on loan...", true); getItemsOnLoan task = new getItemsOnLoan(ItemsOnLoan.this, "http://www.trackallthethings.com/mobile-api/items_on_loan.php?user_id=" + Main.user_id); task.execute();//from w w w.j ava 2 s. c o m Button back = (Button) findViewById(R.id.backfromloan); back.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (itemsOnLoanAdapter != null) itemsOnLoanAdapter.clear(); finish(); } }); }
From source file:li.klass.fhem.fragments.SendCommandFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); final View view = inflater.inflate(R.layout.command_execution, container, false); Button sendButton = (Button) view.findViewById(R.id.send); sendButton.setOnClickListener(new View.OnClickListener() { @Override/*from ww w. ja v a 2s . co m*/ public void onClick(View button) { EditText editText = (EditText) view.findViewById(R.id.input); String command = editText.getText().toString(); sendCommandIntent(command); } }); ListView recentCommandsList = (ListView) view.findViewById(R.id.command_history); recentCommandsAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1); recentCommandsList.setAdapter(recentCommandsAdapter); recentCommandsList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { String command = recentCommands.get(position); sendCommandIntent(command); } }); return view; }
From source file:com.daiv.android.twitter.listeners.InteractionClickListener.java
@Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { HoloTextView title = (HoloTextView) view.findViewById(R.id.title); String mTitle = title.getText().toString(); HoloTextView text = (HoloTextView) view.findViewById(R.id.text); String mText = text.getText().toString(); // get the datasource ready to read/write InteractionsDataSource data = InteractionsDataSource.getInstance(context); if (mTitle.contains(context.getResources().getString(R.string.mentioned_by))) { // this is a mention if (MainDrawerArrayAdapter.current < 3) { new Handler().postDelayed(new Runnable() { @Override/*from w ww .ja v a 2 s .com*/ public void run() { try { drawer.closeDrawer(Gravity.END); } catch (Exception e) { // landscape mode } } }, 300); viewPager.setCurrentItem((mentionsPage), true); } else { final int pos = i; try { drawer.closeDrawer(Gravity.END); } catch (Exception e) { // landscape mode } new Thread(new Runnable() { @Override public void run() { Intent intent = new Intent(context, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); intent.putExtra("page_to_open", mentionsPage); intent.putExtra("from_drawer", true); sharedPreferences.edit().putBoolean("should_refresh", false).commit(); try { Thread.sleep(400); } catch (Exception e) { } try { context.startActivity(intent); ((Activity) context).overridePendingTransition(0, 0); ((Activity) context).finish(); } catch (Exception e) { e.printStackTrace(); } } }).start(); } } else if (mTitle.contains(context.getResources().getString(R.string.retweeted)) || mTitle.contains(context.getResources().getString(R.string.favorited)) || mTitle.contains(context.getResources().getString(R.string.quoted)) || mTitle.contains(context.getResources().getString(R.string.new_favorites)) || mTitle.contains(context.getResources().getString(R.string.new_retweets)) || mTitle.contains(context.getResources().getString(R.string.new_quotes))) { // it is a retweet or favorite try { drawer.closeDrawer(Gravity.END); } catch (Exception e) { // landscape mode } // open up the dialog with the users that retweeted it final String[] fItems = data .getUsers(sharedPreferences.getInt("current_account", 1), i, DrawerActivity.oldInteractions.getText().toString() .equals(context.getResources().getString(R.string.old_interactions))) .split(" "); LayoutInflater factory = LayoutInflater.from(context); View content = factory.inflate(R.layout.interaction_dialog, null); TextView textView = (TextView) content.findViewById(R.id.text); textView.setText(mText); ListView lv = (ListView) content.findViewById(R.id.list); lv.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_selectable_list_item, fItems)); AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setView(content); AlertDialog alert = builder.create(); alert.show(); } else if (mTitle.contains(context.getResources().getString(R.string.followed))) { // someone new followed you try { drawer.closeDrawer(Gravity.END); } catch (Exception e) { // landscape mode } // a new follower, open up the followers profile String username = mTitle.substring(mTitle.indexOf("@") + 1, mTitle.indexOf(" ")); } else if (mTitle.contains(context.getResources().getString(R.string.tweeted))) { try { drawer.closeDrawer(Gravity.END); } catch (Exception e) { // landscape mode } // a new follower, open up the followers profile String username = mTitle.substring(mTitle.indexOf("@") + 1, mTitle.indexOf(" ")); } // mark it read in the sql database data.markRead(sharedPreferences.getInt("current_account", 1), i); // tell the system to refresh the notifications when the user opens the drawer again sharedPreferences.edit().putBoolean("new_notification", true).commit(); }
From source file:com.proma.Nerd.Main_Page.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);//from www.j a v a 2 s . c o m ListView listView = (ListView) findViewById(R.id.listView); NewsControler newsControler = new NewsControler(); try { ArrayList<News> newses = newsControler.getLatestNews(); NewsAdapter adapter = new NewsAdapter(getApplicationContext(), 0, newses); listView.setAdapter(adapter); } catch (JSONException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } final Typeface fontsStyle = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/byekan.ttf"); ViewGroup root = (ViewGroup) findViewById(R.id.root); setFont(root, fontsStyle); }
From source file:app.com.example.android.sunshine_tutorial.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { List<String> weekForecast = new ArrayList<String>(); mForecastAdapter = new ArrayAdapter<String>(getActivity(), R.layout.list_item_forecast, R.id.list_item_forecast_textview, weekForecast); View rootView = inflater.inflate(R.layout.fragment_main, container, false); ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast); listView.setAdapter(mForecastAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override/*w w w . j a v a 2s . c o m*/ public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String forecast = mForecastAdapter.getItem(position); Intent goToDetails = new Intent(getActivity(), DetailActivity.class); goToDetails.putExtra(Intent.EXTRA_TEXT, forecast); startActivity(goToDetails); } }); return rootView; }
From source file:com.digitalconstruction.myapplication.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The ArrayAdapter will take data from a source and // use it to populate the ListView it's attached to. mForecastAdapter = new ForecastAdapter(getActivity(), null, 0); View rootView = inflater.inflate(R.layout.fragment_main, container, false); // Get a reference to the ListView, and attach this adapter to it. ListView mListView = (ListView) rootView.findViewById(R.id.listview_forecast); mListView.setAdapter(mForecastAdapter); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override//from w w w . j ava 2 s .c om public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { Cursor cursor = mForecastAdapter.getCursor(); if (cursor != null && cursor.moveToPosition(position)) { ((Callback) getActivity()).onItemSelected(cursor.getString(COL_WEATHER_DATE)); } mPosition = position; } }); // If there's instance state, mine it for useful information. // The end-goal here is that the user never knows that turning their device sideways // does crazy lifecycle related things. It should feel like some stuff stretched out, // or magically appeared to take advantage of room, but data or place in the app was never // actually *lost*. if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_KEY)) { // The listview probably hasn't even been populated yet. Actually perform the // swapout in onLoadFinished. mPosition = savedInstanceState.getInt(SELECTED_KEY); } mForecastAdapter.setUseTodayLayout(mUseTodayLayout); return rootView; }
From source file:com.irccloud.android.activity.QuickReplyActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_quick_reply); if (getIntent().hasExtra("cid") && getIntent().hasExtra("bid")) { onNewIntent(getIntent());//from w w w .j a va 2s . c om } else { finish(); return; } final ImageButton send = (ImageButton) findViewById(R.id.sendBtn); final EditText message = (EditText) findViewById(R.id.messageTxt); message.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) { if (actionId == EditorInfo.IME_ACTION_SEND && message.getText() != null && message.getText().length() > 0) send.performClick(); return true; } }); message.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View view, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER && message.getText() != null && message.getText().length() > 0) send.performClick(); return false; } }); send.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (message.getText() != null && message.getText().length() > 0) { Intent i = new Intent(RemoteInputService.ACTION_REPLY); i.setComponent(new ComponentName(getPackageName(), RemoteInputService.class.getName())); i.putExtras(getIntent()); i.putExtra("reply", message.getText().toString()); startService(i); finish(); } } }); ListView listView = (ListView) findViewById(R.id.conversation); listView.setAdapter(adapter); }
From source file:at.alladin.rmbt.android.map.RMBTMapFilterFragment.java
protected void populateList(List<ServerOption> optionList, boolean isRoot) { this.isRoot = isRoot; this.currentOptionList = optionList; final RMBTMainActivity activity = getRMBTMainActivity(); final SectionListAdapter sectionListAdapter = new SectionListAdapter(activity, R.layout.preferences_category, !isRoot); // add filter options if (optionList != null && optionList.size() > 0) { for (final ServerOption option : optionList) { if (option.isEnabled()) { if (option.getOptionList() != null && option.getOptionList().size() > 0 && !options.isAnyChildSelected(option)) { options.select(option.getOptionList().get(0)); }/*from ww w .j a v a2 s . c o m*/ sectionListAdapter.addSection(option.getTitle(), new MapListSectionAdapter(activity, option, isRoot)); } } } final ListView listView = (ListView) view.findViewById(R.id.valueList); listView.setAdapter(sectionListAdapter); listView.setItemsCanFocus(true); listView.setOnItemClickListener(this); }
From source file:com.example.android.navigationdrawerexample.activities.MainActivity.java
private void setUpDrawerList(ListView drawerList) { // set up the drawer's list view with items and click listener drawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, drawerTitles)); drawerList.setOnItemClickListener(new DrawerItemClickListener()); }
From source file:com.nttec.everychan.ui.FavoritesFragment.java
private ListView getListView(List<Database.FavoritesEntry> list) { ListView lv = (ListView) inflater.inflate(R.layout.favorites_listview, viewPager, false); lv.setAdapter(new FavoritesAdapter(list, activity)); lv.setOnItemClickListener(this); registerForContextMenu(lv);/*from w w w . j a va 2 s . c o m*/ return lv; }