Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to get a list item position by clicking the button inside it?
    primarykey
    data
    text
    <p>actually I've read some previous questions about this...</p> <p>this is the code that I use</p> <pre><code>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); </code></pre> <p>and class myAdapter</p> <pre><code>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); } }; </code></pre> <p>However, when I click the button, I still get a lot of errors like this:</p> <pre><code>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) </code></pre> <p>That's it! I hope it won't be so difficult to be figured out!</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload