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 4272570
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:35:43+00:00 2026-05-21T07:35:43+00:00

actually I’ve read some previous questions about this… this is the code that I

  • 0

actually I’ve read some previous questions about this…

this is the code that I use

auto = (ListView)findViewById(R.id.auto);
String[] projection = new String[] {Browser.BookmarkColumns._ID,Browser.BookmarkColumns.TITLE,Browser.BookmarkColumns.URL};

    String[] displayFields = new String[] {Browser.BookmarkColumns.TITLE, Browser.BookmarkColumns.URL};

    int[] displayViews = new int[] { R.id.text1,R.id.text2 };

    Cursor cur = managedQuery(android.provider.Browser.BOOKMARKS_URI,projection, null, null, null);

    //auto.setAdapter(new SimpleCursorAdapter(this, R.layout.mylist, cur,displayFields, displayViews));

    myAdapter apt = new myAdapter(this, R.layout.mylist, cur,displayFields, displayViews);
    auto.setAdapter(apt);

and class myAdapter

class myAdapter extends SimpleCursorAdapter{

    private Cursor c;
    private Context context;


    public myAdapter(Context context, int layout, Cursor c, String[] from,
            int[] to) {
        super(context, layout, c, from, to);
        // TODO Auto-generated constructor stub
        this.c = c;
        this.context = context;
        AutoList att = new AutoList();
        mListView = att.auto;

    }

    @Override
    public View getView(int pos, View inView, ViewGroup parent) {
           View vix = inView;

           if (vix == null) {
                LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                vix = inflater.inflate(R.layout.mylist, null);
           }
           this.c.moveToPosition(pos);      

           String title = this.c.getString(this.c.getColumnIndex(Browser.BookmarkColumns.TITLE));

           String cont = this.c.getString(this.c.getColumnIndex(Browser.BookmarkColumns.URL));

               TextView text1 = (TextView) vix.findViewById(R.id.text1);
               text1.setText(title);
               TextView text2 = (TextView) vix.findViewById(R.id.text2);
               text2.setText(cont);
               Button butt = (Button) vix.findViewById(R.id.button);
               butt.setOnClickListener(mButt);
               return vix;
    }

    private OnClickListener mButt = new OnClickListener() {
        @Override
        public void onClick(View v) {
        final int position = mListView.getPositionForView((View) v.getParent());
            Log.v("BUTT", "Title clicked, row "+position);
        }
    };

However, when I click the button, I still get a lot of errors like this:

04-10 22:30:55.152: ERROR/AndroidRuntime(695): FATAL EXCEPTION: main
04-10 22:30:55.152: ERROR/AndroidRuntime(695): java.lang.NullPointerException
04-10 22:30:55.152: ERROR/AndroidRuntime(695):     at             com.auto2.AutoList$myAdapter$1.onClick(AutoList.java:113)
04-10 22:30:55.152: ERROR/AndroidRuntime(695):     at   android.view.View.performClick(View.java:2408)
04-10 22:30:55.152: ERROR/AndroidRuntime(695):     at   android.view.View$PerformClick.run(View.java:8816)
04-10 22:30:55.152: ERROR/AndroidRuntime(695):     at android.os.Handler.handleCallback(Handler.java:587)
04-10 22:30:55.152: ERROR/AndroidRuntime(695):     at   android.os.Handler.dispatchMessage(Handler.java:92)
04-10 22:30:55.152: ERROR/AndroidRuntime(695):     at android.os.Looper.loop(Looper.java:123)
04-10 22:30:55.152: ERROR/AndroidRuntime(695):     at android.app.ActivityThread.main(ActivityThread.java:4627)
04-10 22:30:55.152: ERROR/AndroidRuntime(695):     at java.lang.reflect.Method.invokeNative(Native Method)
04-10 22:30:55.152: ERROR/AndroidRuntime(695):     at java.lang.reflect.Method.invoke(Method.java:521)
04-10 22:30:55.152: ERROR/AndroidRuntime(695):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-10 22:30:55.152: ERROR/AndroidRuntime(695):     at   com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-10 22:30:55.152: ERROR/AndroidRuntime(695):     at   dalvik.system.NativeStart.main(Native Method)

That’s it!
I hope it won’t be so difficult to be figured out!

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-21T07:35:44+00:00Added an answer on May 21, 2026 at 7:35 am

    ListView with Clickable Buttons!!!

    Well…., here’s the rough method to solve my problem SO FAR….

    item.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:orientation="horizontal"
                android:layout_height="wrap_content">
    <TextView android:id="@+id/showTv"
          android:layout_alignParentLeft="true"
          android:gravity="center_vertical"
          android:textSize="24dip"
          android:layout_height="wrap_content"
          android:layout_width="wrap_content" /> 
     <RelativeLayout android:id="@+id/jjjj"
                     android:layout_alignParentRight="true"
                     android:layout_height="wrap_content"
                     android:layout_width="wrap_content">        
          <Button android:id="@+id/gointoBt"
                   android:focusable="false"
                   android:layout_alignParentRight="true"
                   android:text="abc"
                   android:layout_height="wrap_content"
                   android:layout_width="wrap_content"/> 
          <Button android:id="@+id/chooseBt"
                  android:layout_toLeftOf="@id/gointoBt"
                  android:layout_marginRight="10dip"
                  android:text="text"
                  android:focusable="false"
                  android:layout_height="wrap_content"
                  android:layout_width="wrap_content"/>
      </RelativeLayout> 
    

    MySimpleAdapter:

    import ........;
    
    public class MySimpleAdapter extends SimpleAdapter {
    
    private final Context context;
    private List<Map<String, Object>> data;
    private int resource;
    private String[] from;
    private int[] to;
    
    public MySimpleAdapter(Context context,List<? extends Map<String, ?>> data, int resource, String[] from,
    int[] to) {
       super(context, data, resource, from, to);
       this.context=context;
       this.data=(List<Map<String, Object>>) data;
       this.resource=resource;
       this.from=from;
       this.to=to;
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    
       LayoutInflater inflater = ((Activity)context).getLayoutInflater();
       View rowView = inflater.inflate(resource, null, true); 
       Map<String, Object> medMap=data.get(position);
       final TextView[] showTv=new TextView[from.length]; 
    
       for (int i = 0; i < from.length; i++) { 
        showTv[i]=(TextView)rowView.findViewById(to[i]);
        showTv[i].setText(""+medMap.get(from[i]));
       }
    Button btn=(Button)rowView.findViewById(R.id.gointoBt);
       Button.OnClickListener mOkOnClickListener = new Button.OnClickListener()
          {
             public void onClick(View v) {
             Log.v("ttttttt", ""+showTv[0].getText());
             Toast.makeText(context,""+showTv[0].getText(), Toast.LENGTH_LONG).show();
             }
         };
     btn.setOnClickListener(mOkOnClickListener); 
    
         Button btn2=(Button)rowView.findViewById(R.id.chooseBt);
       Button.OnClickListener mOkOnClickListener2 = new Button.OnClickListener()
          {
              public void onClick(View v) {
              Log.v("hhhhhhh", ""+showTv[0].getText());
              Toast.makeText(context,"abc"+showTv[0].getText(), Toast.LENGTH_LONG).show();
              }
          };
       btn2.setOnClickListener(mOkOnClickListener2);     
       return rowView; 
    }
    }
    

    Activty:

    import .......;
    
    public class   ActivityMain extends Activity {
    
    ListView listview;
    List<Map<String,Object>> data;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setTitle("My work");
       prepareData(); 
       listview =new ListView(this);
       MySimpleAdapter adapter=new MySimpleAdapter(this,data,R.layout.item,new String[]      {"uu"},new int[]{R.id.showTv});
    
       listview.setAdapter(adapter);                            
         setContentView(listview);
    
    }
    private void prepareData(){
       data=new ArrayList<Map<String,Object>>();
       Map<String,Object> item;
       item=new HashMap<String,Object>();
       item.put("uu", "hello");
       data.add(item);
       item=new HashMap<String,Object>();
       item.put("uu", "myyou");
       data.add(item);
       item=new HashMap<String,Object>();
       item.put("uu", "piero");
       data.add(item);
    }
    
    }
    

    Thanks for that Man that is so kind to provide this AWESOME yet Mightiest tutorial….
    which anyone here couldn’t give to the noobs….

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

Sidebar

Related Questions

actually this is not hang status, i mean..it slow response, so in that case,
Actually this is my code: echo <pre>; // get current vars $p1 = isset($_GET['p1'])
Actually I am able to use empty listview in my application when I am
Actually these are 3 questions: Which optimization algorithm should I use to optimize the
Actually my previous question got me thinking and I realized that reversing a Dictionary
Actually I've a problem with compiling some library with intel compiler. This same library
Actually I have an application that is using a WebService to retrieve some clients
Actually I'm always using Generic Collections and I frequently use List<>. Some scenarios I
Actually I have two questions. (1) Is there any reduction in processing power or
Actually, almost exactly the same thing. A matrix of small views that would expand

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.