Using RxBiding inside a custom view - android

What's the best practice when you want to emit an Observable with RxView.clicks(mCustomView), but a custom action is also needed inside the View itself?
Multiple subscribers? One being in charge with the custom action inside the View?
Or, perhaps better, using Observable.map() and make the change this way? Then the Observable must reside inside the View.
Or another solution? What do you think? Thanks.

Related

How to implement Android Multi-item listview like iOS UITableView

Now I am implementing chat screen in an Android App.
the use of the adapter pattern of ListView seems to be the best one cell.
You know you need a cell of a different type of user messages, photos, videos, dates, announcements, etc in chat screen.
Conventional methods that I know of is two things.
In getView() method, create each time a new type of cell.
First of all, put all the item and ,in getView() method, adjust the UI layout by VISIBLE/GONE options.
The second method is better i thought, but this method is still a waste of memory and complexity to implement.
For UITableView of iOS generate multiple queue by the number of type of cell. It is efficiently in Multi-Item ListView.
there any easy way to implement as iOS?
Use RecyclerView instead of ListView.
Create xml file for each item view. Create ViewHolder for each file xml.
Inside Adapter of RecyclerView override getItemViewType() return view type correspond with it's position. Override onCreateViewHodlerwhich return ViewHolder correspond with view type. Finally, override onBindViewHolder bind your data to your layout.
Consider using this library JSQMessagesViewController its very flexible and scalable.

Android Clean Code: Handle Click Events in complex GridView

not sure if SO is the right place for this kind of question but here it goes.
I find it relatively hard to write clean code in Android. One problem I struggle with repeatedly are click events in GridView items. Say I have a complex layout (in a custom UI-element) that I inflate for each GridView item that contains multiple Buttons. A button click yields multiple events like database modifications, display of dialogs etc.
If I would handle click events inside those UI elements this would look like as follows:
Fragment -> GridViewAdapter -> MyGridViewItem -> OnClickButton1() -> modifyDB()
I don't want the MyGridViewItem to know about any DB modifications or stuff like that. Or in other words: I don't want to handle those events deep down in my code, but I'm not sure how else to handle them.
Should I use an interface and let either my Adapter or the fragment that creates that adapter implement that interface? Is this considered clean architecture? I couldn't find a clean architecture tutorial that uses adapters and complex layouts.
Thanks for any advice.

Android: Creating custom view and adding it to layout dynamically

I want to create a custom view with some text and two buttons all on one line. I need to be able to add multiple (any number) of these views to an existing layout dynamically (needs to be able to scroll). I want to pass a custom object to the view and set the text and buttons. I need access to the button event handlers from the activity. I've looked a little into custom views but I'm still at a loss for how to do what I want. I'm used to .NET custom controls, and I'm looking for the same effect. Any help or example code would be greatly appreciated.
What you want is custom compound view. You should write you own class (usually extending one of the layouts) and whole behavior, inflate the layout the way you want etc.
More of it: http://developer.android.com/guide/topics/ui/custom-components.html
This one helped me a lot too: http://javatechig.com/android/creating-custom-and-compound-views-in-android-tutorial
If you use list activity or list fragment, you will automatically have the many features you have asked for. You only need to create a adapter class for your listview. You can define your layout for your row view(buttons, text etc..) Try to look at the examples on the web for cusom adapter and lists.

How to switch an android view based on a condition

I am creating an Android application that will mainly consists of ListViews in each activity. What I hope to achieve is a mechanism that will check to see if network connectivity is present and if so then then the data should be retrieved and supplied to the ListView. If there's no data present or the internet connection is unavailable then a seperate view should be loaded.
Which way is most efficient do to this. So far I have seen answers about using a ViewSwitcher or Viewflipper but I am not sure that's the right approach. Should I use fragments and then load a particular fragment based on the condition that was met? I just need some advice on how to accomplish this.
Have you considered just swapping the adapter? This question might be of some use to you.
I guess you might add some kind of factory method that will decide what adapter to instantiate depending on connectivity availability. Thus you will control both the data to be used and the appearance of list entries (I assume you will be using some custom extension of one of the existing adapters).
The best way is going to be to use the emptyView that's provided as part of the AdapterView base class. You just set the adapter as per usual, but if no data is retrieved (i.e. your adapter's data source is empty) you will show the empty view in place of the list. This empty view can be anything you want it to be.
As #Ivan says you should consider setting adapters in a dinamic way.
And about the fragments thing, only consider using independent fragments (or ListFragments) for this if you are going to re-use that fragments in other activities to avoid code duplication.

List item container like whatsapp

I'm trying to get this effect on a list item in a list
https://ssl.gstatic.com/android/market/com.whatsapp/ss-2-320-480-160-0-a637ec45d9d24eb0f50c610657654007223dbe19
What do I have to do - override a LayoutContainer and implement my own onDraw method?
I'm not very good when it comes to graphics/drawing (in code) so can someone give me some starting ideas on how to implement this?
Thanks,
In general it would be much easier. define a 9-patch that can expand that is the background "bubble" and will serve as the background tot he listviewitem. you could dynamically add views (images, textviews, etc) depending on content, or if your needs are simpler, you could just have a single listviewItem.

Categories

Resources