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

  • Home
  • SEARCH
  • 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 6881159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:04:20+00:00 2026-05-27T05:04:20+00:00

I created a ViewBinder , to hold my items in a ListView , which

  • 0

I created a ViewBinder, to hold my items in a ListView, which get its contents from a SimpleCursorAdapter and in this there’s a ImageButton. I successfully get the list but the ImageButton just won’t respond to my onclick event to bring a string from the data base to another Activity. That is the problem I have.

public class ChannelViewBinder implements SimpleCursorAdapter.ViewBinder {
    private ChannelDB mDB;
        public boolean setViewValue(View view, final Cursor cursor, int columnIndex) {
            final Context mContext = null;
                if(view instanceof ImageView) {
                        ImageView iv = (ImageView) view;
                        byte[] img = cursor.getBlob(columnIndex);
                        iv.setImageBitmap(BitmapFactory.decodeByteArray(img, 0, img.length));
                        return true;
                }

              if(view instanceof ImageButton) {
                           ImageButton ib = (ImageButton) view;
                        ib.setOnClickListener(new  View.OnClickListener() {     
                            @Override
                            public void onClick(View v) {

                                String dblink = cursor.getString(cursor.getColumnIndex(mDB.KEY_DBLINK));
                                Intent intent = new Intent();
                                intent.setClass(mContext, Doubanframe.class);
                                Bundle bunde = new Bundle();
                                bunde.putString("dblink",dblink);
                                intent.putExtras(bunde);
                                }
                            });

                }
                return false;
        }
}

and below is my MainActivity class:

private Button likebutton;
    private ImageButton about;
    private ChannelDB mDB;
    private ListView channellist;
    private Cursor c;


    @Override    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        likebutton=(Button) findViewById(R.id.share);
        about =(ImageButton)findViewById(R.id.about);
        channellist = (ListView) findViewById(R.id.Channel);

        mDB = new ChannelDB(this);

        String[] columns = {mDB.KEY_ID, mDB.KEY_POSTER, mDB.KEY_CHANNEL, mDB.KEY_PATH, mDB.KEY_DBLINK};
        String   table   = mDB.channelS_TABLE;

        c = mDB.getHandle().query(table, columns, null, null, null, null, null);

        startManagingCursor(c);

        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
                R.layout.channelview,
                c,
                new String[] {mDB.KEY_POSTER, mDB.KEY_CHANNEL, mDB.KEY_DBLINK},
                new int[] {R.id.poster, R.id.channel, R.id.douban});

        adapter.setViewBinder(new ChannelViewBinder());

        channellist.setAdapter(adapter);

        channellist.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                c.moveToPosition(position);
                Intent intent = new Intent();
                intent.setClass(HDtvs.this,Showlist.class);
                intent .putExtra("path",mDB.KEY_PATH);
                intent .putExtra("cname",mDB.KEY_CHANNEL);
                intent .putExtra("dblink",mDB.KEY_DBLINK);
                startActivity(intent);
            }
        }); 
}
  • 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-27T05:04:20+00:00Added an answer on May 27, 2026 at 5:04 am

    In the onClickListener on your ImageButton you are creating a new Intent, but you don’t seem to call startActivity? You will need to have a reference to some sort of context in order to be able to do so. Your mContext variable appears to be a good candidate for that, although I don’t see it being set to anything but null in the code snippet.

    You can easily add a reference to a valid Context by creating a constructor for your ChannelViewBinder class.

    public class ChannelViewBinder implements SimpleCursorAdapter.ViewBinder {
        private Context mContext = null;
    
        public ChannelViewBinder(Context context) {
            mContext = context;
        }
    ...
    }
    

    You can then later on use it to call mContext.startActivity(intent) in the ImageButton’s onClick. Obviously you will also need to change instantiating the object: adapter.setViewBinder(new ChannelViewBinder(this)), where this will reference your MainActivity class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Created a views.py method to get the data posted from an html form. As
I created a cursor from the one that was described on this post: SQL
Created .NET WCF service, tested it - works. Generated schemas from Data and service
I created a program using dev-cpp and wxwidgets which solves a puzzle. The user
Created application is working toooo slow, looks like there are a lot of memory
Created a button in my aspx file and add its click method in the
created a singleview application with storyboard. Added three viewcontrollers apart from the one view
Created a google map with GMap2 and put pinpoints on there that open up
Created a custom validation attribute and I would like to get it to work
Created by Microsoft as the foundation of its .NET technology, the Common Language Infrastructure

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.