Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7048065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:50:48+00:00 2026-05-28T02:50:48+00:00

here is my code, package com.mjzone.project; public class MyDatabase extends Activity { final protected

  • 0

here is my code,
package com.mjzone.project;

public class MyDatabase extends Activity {

final protected String DATABASE_TABLE = "details";
private MyDatabaseHelper myHelper;
Context mjContext;
SQLiteDatabase myDb;
String[] values = null;

// ====== Constructor for MyDatabse class ==========

public MyDatabase(Context c) {
    mjContext = c;

}

private class MyDatabaseHelper extends SQLiteOpenHelper {

    public MyDatabaseHelper(Context context) {
        super(context, "MapDatabase", null, 1);
        // TODO Auto-generated constructor stub
    }

    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE IF NOT EXISTS "
                + DATABASE_TABLE
                + " ("
                + BaseColumns._ID
                + " INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR NULL, description VARCHAR NULL,latitude VARCHAR NULL, longitude VARCHAR NULL,image BLOB NULL, category VARCHAR NULL)");
        // TODO Auto-generated method stub

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {
        db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
        onCreate(db);
        // TODO Auto-generated method stub

    }

}

// ========= to open connection ==============

public MyDatabaseHelper open() throws Exception {
    myHelper = new MyDatabaseHelper(mjContext);
    myDb = myHelper.getWritableDatabase();

    return myHelper;

}

// ======== to close connection ===============

public void close() throws Exception{
    myHelper.close();

}

// ========= to create entry ==================

public long createEntry(byte[] iimage, String iname, String idescription,String ilatitude, String ilongitude) {

    ContentValues myBundle = new ContentValues();

    myBundle.put("name", iname);
    myBundle.put("description", idescription);
    myBundle.put("latitude", ilatitude);
    myBundle.put("longitude", ilongitude);
    myBundle.put("image", iimage);
    myBundle.put("category", "NT");

    return myDb.insert(DATABASE_TABLE, null, myBundle);

}

// =========== get data ========================

public String[] getData() throws Exception {

    final String[] columns = { BaseColumns._ID, "name", "description","latitude", "longitude", "image", "category" };
    Cursor c = myDb.query(DATABASE_TABLE, columns, null, null, null, null,null);

    int xname = c.getColumnIndex("name");
    int xdescription = c.getColumnIndex("description");
    int xcategory = c.getColumnIndex("image");

    int i = 0;

    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {

        values[i] = c.getString(xcategory) + "\t" + c.getString(xname) + "\t" + c.getString(xdescription);
        i++;

    }
            c.close();
    return values;

}

}

above is the code of the database class and here is the list demo class

public class MyListDemo extends ListActivity{

String[] data; 
@Override
protected void onCreate(Bundle arg0) {
    // TODO Auto-generated method stub
    super.onCreate(arg0);

    try {
        MyDatabase dbObject = new MyDatabase(this);
        dbObject.open();
        data = dbObject.getData();
        MyArrayAdapter adpter = new MyArrayAdapter(this, data);
        setListAdapter(adpter);
        dbObject.close();

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

}

following shows my Array Adapter class

public class MyArrayAdapter extends ArrayAdapter<String> {

private String[] values;
private Context context;

public MyArrayAdapter(Context context, String[] values) {
    super(context, R.layout.rowlayout, values);
    this.context = context;
    this.values = values;
    // TODO Auto-generated constructor stub
}

public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView = inflater.inflate(R.layout.rowlayout, parent, false);
    TextView textView = (TextView) rowView.findViewById(R.id.label);
    ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
    textView.setText(values[position]);
    // Change the icon for Windows and iPhone
    String s = values[position];

    if (s.startsWith("NT")) {
        imageView.setImageResource(R.drawable.ic_launcher);
    } else {
        imageView.setImageResource(R.drawable.camera);
    }

    return rowView;
}

this is my layout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<ImageView
    android:id="@+id/icon"
    android:layout_width="22px"
    android:layout_height="22px"
    android:layout_marginLeft="4px"
    android:layout_marginRight="10px"
    android:layout_marginTop="4px"
    android:src="@drawable/ic_launcher" >
</ImageView>

<TextView
    android:id="@+id/label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@+id/label"
    android:textSize="30px" >
</TextView>

but list view is not populated for some reason. it shows only the black screen. Could anyone please help me?

thanks…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:50:49+00:00Added an answer on May 28, 2026 at 2:50 am

    Try using SimpleCursorAdapter instead like this: Create a layout with 1 imageView and 2 TextViews(TV1,TV2),let us call it listview_item

    Cursor c = myDb.query(DATABASE_TABLE, columns, null, null, null, null,null);
    
    String[] from={"category","name","description"}
    int[] to={R.id.IV1,R.id.TV1,R.id.TV2}
    
    SimpleCursorAdapter adapter=new SimpleCursorAdapter(this, listview_item, c, from, to);
    
    adapter.setViewBinder(new ViewBinder() {
    
        public boolean setViewValue(View aView, Cursor aCursor, int aColumnIndex) {
            if(aColumnIndex==aCursor.getColumnIndex("category")){
                String s = aCursor.getString(aCursor.getColumnIndex("category"));
    
                if (s.startsWith("NT")) {
                    ImageView IV= (ImageView) aView;
                    IV.setImageResource(R.drawable.ic_launcher);
                } else {
                    IV.setImageResource(R.drawable.camera);
                }
                return true;
            }
            return false;
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code: package com.commonsware.android.skeleton; import android.app.Activity; import android.content.Context; import android.hardware.Camera; import android.hardware.Camera.*;
Here a code to demonstrate an annoying problem: class A { public: A(): m_b(1),
Here is my code: package com.AndroidCustomDialog; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException;
Here's my code: package com.eggproject_hu.WPECommerceAdminSales.client; import java.lang.Boolean; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.Window; public class AblakVillogo
I am trying to install MySQLdb package. I found the source code here .
See here: http://code.google.com/p/ie7-js/ Does anyone have any experience or remarks about this javascript? Is
I'm trying to override Variables that are already defined. Here is my code: package
Ok the error is showing up somewhere in this here code if($error==false) { $query
Here is code from MSDN . I don't understand why the work isn't just
enter code here I have a table on SQL server 2005 with bigint primary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.