List of usage examples for android.widget BaseAdapter BaseAdapter
BaseAdapter
From source file:com.aphidmobile.flip.demo.fragment.FlipTextViewFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { flipView = new FlipViewController(inflater.getContext()); flipView.setAdapter(new BaseAdapter() { @Override//from w w w .j a v a 2 s. co m public int getCount() { return 10; } @Override public Object getItem(int position) { return position; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { NumberTextView view; if (convertView == null) { final Context context = parent.getContext(); view = new NumberTextView(context, position); view.setTextSize(context.getResources().getDimension(R.dimen.textSize)); } else { view = (NumberTextView) convertView; view.setNumber(position); } return view; } }); return flipView; }
From source file:de.fahrgemeinschaft.RideListFragment.java
@Override public void onViewCreated(View layout, Bundle savedInstanceState) { super.onViewCreated(layout, savedInstanceState); setListAdapter(new BaseAdapter() { @Override// w w w. j a va 2 s. c o m public int getCount() { return 42; } @Override public View getView(int position, View v, ViewGroup parent) { v = getLayoutInflater(null).inflate(R.layout.view_ride_list_entry, parent, false); // we have default green background if (position % 2 == 0) { v.setBackgroundColor(getResources().getColor(R.color.mediumGreen)); } return v; } @Override public long getItemId(int position) { return 0; } @Override public Object getItem(int position) { return null; } }); }
From source file:com.kogitune.prelollipoptransition.fragment.ListViewFragment.java
@Nullable @Override/* ww w . ja v a 2 s.co m*/ public View onCreateView(final LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View inflate = inflater.inflate(R.layout.fragment_list_view, container, false); final ListView listView = (ListView) inflate.findViewById(R.id.list); listView.setAdapter(new BaseAdapter() { @Override public int getCount() { return 10; } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { return inflater.inflate(R.layout.list_row, parent, false); } }); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final Intent intent = new Intent(getContext(), SubActivity.class); ActivityTransitionLauncher.with(getActivity()).from(view.findViewById(R.id.image)).launch(intent); } }); return inflate; }
From source file:com.unidev.app.testapp.activity.MainFragment.java
@Override public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.main, container, false); ListView listView = (ListView) view.findViewById(R.id.list); final FlatFileStorage currentPage = Core.getInstance().currentPage(); final ArrayList<Poly> polyArrayList = new ArrayList<>(currentPage.list()); listView.setAdapter(new BaseAdapter() { @Override//from w ww .ja v a2 s .co m public int getCount() { return polyArrayList.size(); } @Override public Object getItem(int position) { return position; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View view, ViewGroup parent) { if (view == null) { view = inflater.inflate(R.layout.list_item, null); } final Poly poly = polyArrayList.get(position); TextView item = (TextView) view.findViewById(R.id.item); item.setText(poly._id() + ""); final Button button = (Button) view.findViewById(R.id.favs); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { AlertDialog.Builder builder = new AlertDialog.Builder(MainFragment.this.getActivity()); builder.setTitle("Poly record"); builder.setMessage(poly + ""); builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); AlertDialog dialog = builder.create(); dialog.show(); } }); return view; } }); return view; }
From source file:uk.org.ngo.squeezer.itemlist.dialog.AlbumViewDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { final AlbumListActivity activity = (AlbumListActivity) getActivity(); AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setTitle(activity.getServerString(ServerString.ALBUM_DISPLAY_OPTIONS)); builder.setAdapter(new BaseAdapter() { @Override//from www. j a v a 2 s . c o m public boolean areAllItemsEnabled() { return false; } @Override public boolean isEnabled(int position) { return (position != POSITION_SORT_LABEL); } @Override public int getCount() { return AlbumListLayout.values().length + 1 + AlbumsSortOrder.values().length; } @Override public Object getItem(int i) { return null; } @Override public long getItemId(int i) { return i; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (position < POSITION_SORT_LABEL) { CheckedTextView textView = (CheckedTextView) activity.getLayoutInflater() .inflate(android.R.layout.select_dialog_singlechoice, parent, false); AlbumListLayout listLayout = AlbumListLayout.values()[position]; textView.setCompoundDrawablesWithIntrinsicBounds(listLayout.icon, 0, 0, 0); textView.setText(activity.getServerString(listLayout.serverString)); textView.setChecked(listLayout == activity.getListLayout()); return textView; } else if (position > POSITION_SORT_LABEL) { CheckedTextView textView = (CheckedTextView) activity.getLayoutInflater() .inflate(android.R.layout.select_dialog_singlechoice, parent, false); position -= POSITION_SORT_START; AlbumsSortOrder sortOrder = AlbumsSortOrder.values()[position]; textView.setText(activity.getServerString(sortOrder.serverString)); textView.setChecked(sortOrder == activity.getSortOrder()); return textView; } TextView textView = new TextView(activity, null, android.R.attr.listSeparatorTextViewStyle); textView.setText( getString(R.string.choose_sort_order, activity.getItemAdapter().getQuantityString(2))); return textView; } }, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int position) { if (position < POSITION_SORT_LABEL) { activity.setListLayout(AlbumListLayout.values()[position]); dialog.dismiss(); } else if (position > POSITION_SORT_LABEL) { position -= POSITION_SORT_START; activity.setSortOrder(AlbumsSortOrder.values()[position]); dialog.dismiss(); } } }); return builder.create(); }
From source file:andlabs.lounge.lobby.ui.ChatFragment.java
@Override public View onCreateView(final LayoutInflater infl, ViewGroup p, Bundle b) { final View chat = infl.inflate(R.layout.fragment_chat, p, false); mChatEditText = ((EditText) chat.findViewById(R.id.msg_field)); ((ImageButton) chat.findViewById(R.id.btn_send)).setOnClickListener(this); ((ListView) chat.findViewById(R.id.list)).setAdapter(new BaseAdapter() { @Override/*from www . j a v a 2 s . c o m*/ public int getCount() { return mConversation.size(); } @Override public View getView(int position, View view, ViewGroup parent) { if (view == null) view = infl.inflate(R.layout.chat_list_entry, null); final ChatMessage msg = mConversation.get(position); ((TextView) view.findViewById(R.id.sender)).setText(msg.getPlayerName()); ((TextView) view.findViewById(R.id.msg_text)).setText(msg.getMessage()); return view; } @Override public long getItemId(int position) { return 0; } @Override public Object getItem(int position) { return null; } }); // http://code.google.com/p/android/issues/detail?id=2516 mChatEditText.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) { onClick(null); return true; } return false; } }); return chat; }
From source file:net.soulwolf.widget.parallaxlayout.sample.SimpleFragment.java
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mListView = (ParallaxListView) view.findViewById(R.id.list1); ParallaxLayoutPresenter.attachParallaxScrollable(getActivity(), mPosition, mListView); mListView.setAdapter(new BaseAdapter() { @Override/*from w w w . j a va 2 s .c o m*/ public int getCount() { return 50; } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { TextView textView; if (convertView == null) { textView = (TextView) LayoutInflater.from(getActivity()).inflate(R.layout.simple_text, null); } else { textView = (TextView) convertView; } textView.setText("SimpleFragment : " + position + ",pager:" + mPosition); return textView; } }); }
From source file:eu.andlabs.studiolounge.chat.ChatFragment.java
@Override public View onCreateView(final LayoutInflater infl, ViewGroup p, Bundle b) { final View chat = infl.inflate(R.layout.chat, p, false); mChatEditText = ((EditText) chat.findViewById(R.id.msg_field)); ((ImageButton) chat.findViewById(R.id.btn_msgSend)).setOnClickListener(this); ((ListView) chat.findViewById(R.id.list)).setAdapter(new BaseAdapter() { @Override/*from ww w .j a v a 2s . co m*/ public int getCount() { return mConversation.size(); } @Override public View getView(int position, View view, ViewGroup parent) { if (view == null) view = infl.inflate(R.layout.chat_list_entry, null); final ChatMessage msg = mConversation.get(position); final Player player = new Player(msg.player); ((TextView) view.findViewById(R.id.sender)).setText(player.getShortPlayername()); ((TextView) view.findViewById(R.id.msg_text)).setText(msg.text); return view; } @Override public long getItemId(int position) { return 0; } @Override public Object getItem(int position) { return null; } }); // http://code.google.com/p/android/issues/detail?id=2516 mChatEditText.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) { onClick(null); return true; } return false; } }); return chat; }
From source file:com.android.development.ExceptionBrowser.java
@Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); Cursor cursor = getContentResolver().query(Checkin.Crashes.CONTENT_URI, new String[] { Checkin.Crashes._ID, Checkin.Crashes.DATA }, null, null, null); if (cursor != null) { startManagingCursor(cursor);//from w w w. java 2 s . c om setListAdapter(new CursorAdapter(this, cursor, true) { public View newView(Context context, Cursor c, ViewGroup v) { return new CrashListItem(context); } public void bindView(View view, Context c, Cursor cursor) { CrashListItem item = (CrashListItem) view; try { String data = cursor.getString(1); CrashData crash = new CrashData(new DataInputStream( new ByteArrayInputStream(Base64.decodeBase64(data.getBytes())))); ThrowableData exc = crash.getThrowableData(); item.setText(exc.getType() + ": " + exc.getMessage()); item.setCrashData(crash); } catch (IOException e) { item.setText("Invalid crash: " + e); Log.e(TAG, "Invalid crash", e); } } }); } else { // No database, no exceptions, empty list. setListAdapter(new BaseAdapter() { public int getCount() { return 0; } public Object getItem(int position) { throw new AssertionError(); } public long getItemId(int position) { throw new AssertionError(); } public View getView(int position, View convertView, ViewGroup parent) { throw new AssertionError(); } }); } }
From source file:com.google.reviewit.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().permitAll().build()); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/* ww w . ja v a 2 s .c o m*/ if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); } drawer = (DrawerLayout) findViewById(R.id.drawer); list = (ListView) findViewById(R.id.mainList); items = new ArrayList<>(); items.add(new Item(SortChangesFragment.class, R.string.app_menu_sort, R.drawable.ic_star_white_16dp, null)); items.add(new Item(ReviewChangesFragment.class, R.string.app_menu_review, R.drawable.ic_feedback_white_18dp, null)); items.add(new Item(SettingsFragment.class, R.string.app_menu_settings, R.drawable.ic_settings_white_18dp, null)); list.setAdapter(new BaseAdapter() { @Override public int getCount() { return items.size(); } @Override public Object getItem(int position) { return items.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = ((LayoutInflater) MainActivity.this .getSystemService(Activity.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.main_list_item, null); } Item item = items.get(position); ((ImageView) convertView.findViewById(R.id.mainListItemIcon)).setImageResource(item.iconId); WidgetUtil.setText(convertView, R.id.mainListItemTitle, getString(item.titleId)); if (item.count != null) { WidgetUtil.setText(convertView, R.id.mainListItemCounter, item.count.toString()); } else { convertView.findViewById(R.id.mainListItemCounter).setVisibility(View.GONE); } return convertView; } }); toggle = new ActionBarDrawerToggle(this, drawer, R.string.app_name, R.string.app_name) { public void onDrawerClosed(View view) { invalidateOptionsMenu(); } public void onDrawerOpened(View drawerView) { invalidateOptionsMenu(); } }; drawer.setDrawerListener(toggle); list.setOnItemClickListener(new ListView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { displayView(position); } }); if (getApp().getPrefs().showIntro) { displayInitialView(new IntroFragment1()); } else if (savedInstanceState == null) { switch (getApp().getPrefs().startScreen) { case REVIEW_SCREEN: displayInitialView(newFragmentInstance(items.get(1).fragmentClass)); break; case SORT_SCREEN: default: displayInitialView(newFragmentInstance(items.get(0).fragmentClass)); break; } } }