How to bind more then one column to a textview

I am curious if there is a way to bind more then one db column to a resource. I need to bind more information to R.id.secondLine then just the difficulty column. But I'm unsure how to go about this? I'm currently subclassing SimpleCursorAdapter. Should I subclass another adapter? If so How to do I go about it?

    Cursor activityHikes = mDbAdapter.fetchAllHikes(false);
    startManagingCursor(activityHikes);

    String[] from = new String[] { ActivityHike.NAME, ActivityHike.DIFFICULTY, ActivityHike.THUMBNAIL};

    int[] to = new int[]{R.id.mainText, R.id.secondLine, R.id.icon};

    HikeAdapter hikes = new HikeAdapter(this, R.layout.hike_row, activityHikes, from, to);
    ListView list = (ListView) this.findViewById(R.id.hikelist);
    list.setAdapter(hikes);

Thanks

For anyone who has this same problem this link helped me alot too. Android: Binding data from a database to a CheckBox in a ListView?


Asked by: Kristian796 | Posted: 20-01-2022






Answer 1

I don't think you can bind more than one column to a view using SimpleCursorAdapter. Your best bet would be to subclass CursorAdapter and implement bindView to do any special formatting you want to the text field.

Answered by: Clark113 | Posted: 21-02-2022



Answer 2

I would implement your own ViewBinder and pass that to your SimpleCursorAdapter. This gives you full access to the cursor when setting the values of each View.

Answered by: Rafael620 | Posted: 21-02-2022



Similar questions

android - Can I hook when user copy or paste on TextView?

When user copy or paste on TextView, Is there anyone explains me what happen on TextView. If some methods called while user click 'Copy' or 'Paste' in menus, I'd like to hook them and replace them with my own one. Here is what I want to do. 1. user copy or paste some string to my TextView. 2. some string copied and paste on my Textview. 3. Before some string is added on Textview, I want to check or change string.


Android TextView Text not getting wrapped

Can anyone tell me what's going wrong with the text? Text longer than one line doesn't wrap to the next line but goes beyond the screen. Following is the code: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="4dip"> <LinearL...


android - How to display HTML in TextView?

I have simple HTML: <h2>Title</h2><br> <p>description here</p> I want to display HTML styled text it in TextView. How to do this?


how to change text in Android TextView

I tried to do this @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); t=new TextView(this); t=(TextView)findViewById(R.id.TextView01); t.setText("Step One: blast egg"); try { Thread.sleep(10000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printSta...


android - Color of the text in TextView changes color

In android, when I press on a TextView, the text changes color (from white to grey). Can you please tell me how can I disable that functionality? Thank you.


android - Can I hook when user copy or paste on TextView?

When user copy or paste on TextView, Is there anyone explains me what happen on TextView. If some methods called while user click 'Copy' or 'Paste' in menus, I'd like to hook them and replace them with my own one. Here is what I want to do. 1. user copy or paste some string to my TextView. 2. some string copied and paste on my Textview. 3. Before some string is added on Textview, I want to check or change string.


Maximum line length on Android TextView

I'm putting a formatted single line text (no \n's) to a noneditable TextView. In the navigation of the program, the text can be changed. On some text, the TextView shrinks to 0x0 pixel and I can see nothing! I added some menus to truncate the text 10 characters each time and I found that if the number of characters are larger than 4470, the TextView shrinks. Splitting the text into several lines by putting \n in be...


Android TextView Text not getting wrapped

Can anyone tell me what's going wrong with the text? Text longer than one line doesn't wrap to the next line but goes beyond the screen. Following is the code: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="4dip"> <LinearL...


Ordered lists inside an Android TextView

I want to display an ordered list inside a TextView, for example: 1) item 1 2) item 2 Using the following layout: <TextView android:text="<ol><li>item 1\n</li><li>item 2\n</li></ol> /> I get: item 1 item 2 How can I change the bullets to numbers? Thanks.


android - How to display HTML in TextView?

I have simple HTML: <h2>Title</h2><br> <p>description here</p> I want to display HTML styled text it in TextView. How to do this?


how to change text in Android TextView

I tried to do this @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); t=new TextView(this); t=(TextView)findViewById(R.id.TextView01); t.setText("Step One: blast egg"); try { Thread.sleep(10000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printSta...


android - Color of the text in TextView changes color

In android, when I press on a TextView, the text changes color (from white to grey). Can you please tell me how can I disable that functionality? Thank you.


How can you display upside down text with a textview in Android?

How can you display upside down text with a textview in Android? In my case I have a 2 player game, where they play across from each other. I want to display test to the second player oriented to them. This was the solution I implemented after AaronMs advice The class that does the overriding, bab.foo.UpsideDownText package bab.foo; import android.content.Context; import andr...


textview - How to know all id's that i have in the file main.xml in android?

i'm new at Android world, and i have a doubt, is there any method that give me the name of the id's i create in main.xml? For example i have this: main.xml <TextView android:id="@+id/text1" android:layout_width="70px" android:layout_height="70px" android:text="Google" /> <TextView android:id="@+id/text2" android:layout_width="70px" android:layout_h...


How do I add a newline to a TextView in Android?

When I define a TextView in xml, how do I add a new line to it? \n seems not to work. <TextView android:id="@+id/txtTitlevalue" android:text="Line1 -\nLine2" android:layout_width="54dip" android:layout_height="fill_parent" android:textSize="11px" />






Still can't find your answer? Check out these communities...



Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android



top