I have pictures in my sqlite prepopulated database, i'm using Simplecursortreeadapter to pass data to exepndablelistview , but the app crush when opening a childview with a picture and in logcat i got "UNABLE TO CONVERT STRING TO BLLOB'.
After making some research on internet i discovered(maybe) i have to implement viewbinder which i did ( copy past and addapt to my columns) ..what i have done is based on the answer of this question:https://stackoverflow.com/questions/30388843/unable-to-convert-blob-to-string-using-loadermanager-in-android ..
But The app can't build successfuly now...i think i'm missing something or there is something wrong with my code:
Please help! thanks - public class MainActivity extends AppCompatActivity {
-
ExpandableListView expandableListView;
-
Database mDatabase;
-
-
@Override
-
protected void onCreate(Bundle savedInstanceState) {
-
super.onCreate(savedInstanceState);
-
setContentView(R.layout.activity_main);
-
-
mDatabase = new Database(this);
-
mDatabase.open();
-
-
SimpleCursorTreeAdapter.setViewBinder( new MyViewBinder());
-
-
Cursor cursor = mDatabase.getDatabase();
-
startManagingCursor(cursor);
-
-
String[] childFrom = new String[]{Database.DATABASE_CHILD_1,Database.DATABASE_CHILD_2};
-
String[] groupFrom = new String[]{Database.DATABASE_GROUP_1};
-
-
int[] groupTo = {R.id.group1};
-
int[] childTo = {R.id.child1,R.id.child2};
-
-
SimpleCursorTreeAdapter simplecursortreeAdapter = new ExpandableListViewAdapter(
-
this,
-
cursor,
-
R.layout.list_group,
-
groupFrom,
-
groupTo,
-
R.layout.list_child,
-
childFrom,
-
childTo
-
);
-
-
expandableListView = findViewById(R.id.expandableListview);
-
expandableListView.setAdapter(simplecursortreeAdapter);
-
}
-
-
protected void onDestroy() {
-
super.onDestroy();
-
mDatabase.close();
-
}
-
-
public class MyViewBinder implements ViewBinder {
-
@Override
-
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
-
int viewID = view.getId();
-
switch(viewID){
-
case R.id.child1 :
-
TextView friendName = (TextView) view;
-
String friend_name;
-
friend_name = cursor.getString(cursor.getColumnIndex(Database.DATABASE_CHILD_1));
-
friendName.setText(friend_name);
-
break;
-
-
case R.id.child2 :
-
ImageView contactProfile = (ImageView) view;
-
byte[] imageBytes = cursor.getBlob(cursor.getColumnIndex(Database.DATABASE_CHILD_2));
-
if(imageBytes != null ){
-
// Pic image from database
-
contactProfile.setImageBitmap(BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length));
-
}else {
-
// If image not found in database , assign a default image
-
contactProfile.setBackgroundResource(R.drawable.disorders);
-
}
-
break;
-
}
-
return true;
-
}
-
-
}
-
-
private class ExpandableListViewAdapter extends SimpleCursorTreeAdapter {
-
private ExpandableListViewAdapter(
-
Context context,
-
Cursor cursor,
-
int groupLayout,
-
String[] groupFrom,
-
int[] groupTo,
-
int childLayout,
-
String[] childFrom,
-
int[] childTo) { super(context, cursor, groupLayout, groupFrom, groupTo, childLayout, childFrom, childTo); }
-
-
protected Cursor getChildrenCursor(Cursor groupCursor) {
-
return mDatabase.getID(groupCursor.getInt(groupCursor.getColumnIndex(Database.DATABASE_ID)));
-
}
-
-
}
-
-
-
}
-
0 2101 Sign in to post your reply or Sign up for a free account.
Similar topics
by: Nathan |
last post by:
Is there a way to convert a string to a CipherMessage? I am calling a
function that decrypts a CipherMessage and returns the value. The only
problem is when I want to use an encrypted value stored...
|
by: news.hku.hk |
last post by:
could you tell me how can i convet a string to integer??
#include <iostream>
#include <string>
using namespace std;
int main(){
int integer;
string buffer("123456789");
|
by: sarab |
last post by:
Hi,
I have a managed C++ app in which i need to convert String * to char *.
How can i achive this?.
regards
-sarab
|
by: Petr Jakes |
last post by:
Hi,
I am trying to convert string to the "escaped string".
example: from "0xf" I need "\0xf"
I am able to do it like:
a="0xf"
escaped_a=("\%s" % a ).decode("string_escape")
But it looks a...
|
by: XML newbie: Urgent pls help! |
last post by:
function to convert string to 1 dimensional array of long in VB.Net
|
by: Ursula |
last post by:
Is it possible to convert a string in a file. The problem is this:
I have an object string that is a file xml and I want to pass to Deserialize
function, but Deserialize function expect an object...
|
by: Shawn Ferguson |
last post by:
Hello All,
I'm trying to do what I would think would be simple and straightforward, but it is not. I have a 2 textbox on a form, a label, and a button, when I click the botton I want to add the...
|
by: Man4ish |
last post by:
HI ,
I am trying to convert string into char array of characters.but facing problem.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string t="1,2,3,4,5,6";
|
by: Peter |
last post by:
Trying to convert string to byte array.
the following code returns byte array of {107, 62, 194, 139, 64}
how can I convert this string to a byte array of {107, 62, 139, 65}
...
|
by: engteng |
last post by:
How do I convert string to numeric in VB.NET 2003 ?
Example convert P50001 to 50001 or 50001P to 50001 but if P is in middle
then not convert.
Regards,
Tee
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |