java - Button in each row of my dynamic listview is not working? -
i have using data in db , showing in listview each row have given sms button go smsactivity,but while clicking sms button not going anyactiviyt,it there,not showing error or logcat error also
this activity.java
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_list_item2); mdbhelper = new ginfydbadapter(this); mdbhelper.open(); filldata(); registerforcontextmenu(getlistview()); } @suppresslint("newapi") @suppresswarnings("deprecation") private void filldata() { mdbhelper.open(); cursor projectscursor = mdbhelper.fetchallprojects(); //startmanagingcursor(projectscursor); // create array specify fields want display in list (only title) string[] = new string[]{ginfydbadapter.category_column_title,ginfydbadapter.category_column_content,ginfydbadapter.category_column_count}; // , array of fields want bind fields (in case text1) int[] = new int[]{r.id.text2,r.id.text1,r.id.count}; dataadapter = new simplecursoradapter( this, r.layout.activity_row2, projectscursor, from, to, 0); setlistadapter(dataadapter); edittext myfilter = (edittext) findviewbyid(r.id.myfilter); myfilter.addtextchangedlistener(new textwatcher() { public void aftertextchanged(editable s) { } public void beforetextchanged(charsequence s, int start, int count, int after) { } public void ontextchanged(charsequence s, int start, int before, int count) { dataadapter.getfilter().filter(s.tostring()); } }); dataadapter.setfilterqueryprovider(new filterqueryprovider() { public cursor runquery(charsequence constraint) { return mdbhelper.fetchprojectbyname(constraint.tostring()); } }); tts = new texttospeech(this, this); final listview lv = getlistview(); txttext = (textview) findviewbyid(r.id.text1); lv.settextfilterenabled(true); } @override public void ondestroy() { // don't forget shutdown tts! if (tts != null) { tts.stop(); tts.shutdown(); } super.ondestroy(); } public void oninit(int status) { if (status == texttospeech.success) { int result = tts.setlanguage(locale.us); if (result == texttospeech.lang_missing_data || result == texttospeech.lang_not_supported) { log.e("tts", "this language not supported"); } else { //btnaudioprayer.setenabled(true); speakout(); } } else { log.e("tts", "initilization failed!"); } } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. super.oncreateoptionsmenu(menu); menuinflater mi = getmenuinflater(); mi.inflate(r.menu.activity_main1, menu); return true; } @override public boolean onmenuitemselected(int featureid, menuitem item) { createproject(); return super.onmenuitemselected(featureid, item); } private void createproject() { intent = new intent(this, addyourprayeractivity.class); startactivityforresult(i, activity_create); } @override protected void onactivityresult(int requestcode, int resultcode, intent intent) { super.onactivityresult(requestcode, resultcode, intent); filldata(); } private void speakout() { // string text = txttext.gettext().tostring(); // string text = "android speech"; tts.speak(typed, texttospeech.queue_flush, null); } class customadapter extends simplecursoradapter { private layoutinflater minflater; @suppresswarnings("deprecation") public customadapter(context context, int layout, cursor c, string[] from, int[] to) { super(context, layout, c, from, to); // todo auto-generated constructor stub minflater= layoutinflater.from(context); } public view getview(final int position, view convertview, viewgroup parent, cursor cursor) { viewholder holder; if(convertview==null){ convertview= minflater.inflate(r.layout.activity_row2, null); convertview = inflater.inflate(r.layout.activity_row2, parent, false); holder = new viewholder(); holder.tv = (textview) convertview.findviewbyid(r.id.text1); holder.tv1 = (textview) convertview.findviewbyid(r.id.text2); holder.buttonsms = (button) convertview.findviewbyid(r.id.buttonsms); convertview.settag(holder); }else{ holder = (viewholder) convertview.gettag(); } int col1 = cursor.getcolumnindex("title"); final string title = cursor.getstring(col1 ); int col2 = cursor.getcolumnindex("content"); final string content = cursor.getstring(col2 ); holder.tv.settext( title); holder.tv1.settext( content); holder.buttonsms.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { stringbuffer sb2 = new stringbuffer(); sb2.append("title:"); sb2.append(html.fromhtml(title)); sb2.append(",content:"); sb2.append(html.fromhtml(content)); sb2.append("\n"); string strcontactlist1 = (sb2.tostring().trim()); sendsmsdata(strcontactlist1); } }); // bindview(v,context,cursor); return convertview; } public class viewholder { textview tv,tv1; button buttonsms; } } public void sendsmsdata(string strcontactlist1) { intent intent3=new intent(yourprayeractivity.this,sendsmsactivity.class); intent3.putextra("firstkeyname", strcontactlist1); startactivity(intent3); } @override public void onclick(view v) { // todo auto-generated method stub } }
i using simpleadapter fetching data db,after button function using customadapter fetch data listview,class customadapter extper simplecursoradapter
here mention xml file also.
<linearlayout android:id="@+id/share" android:layout_width="0.0dip" android:layout_height="fill_parent" android:layout_weight="1.0" android:background="@drawable/button_new_feed" android:orientation="horizontal" > <button android:id="@+id/buttonsms" android:layout_width="25.0dip" android:layout_height="fill_parent" android:layout_marginleft="4.0dip" android:src="@drawable/sms" /> <imagebutton android:id="@+id/mail" android:layout_width="25.0dip" android:layout_height="fill_parent" android:layout_marginleft="6.0dip" android:src="@drawable/mail" /> </linearlayout>
it hard find out went wrong
you have , customadapter
. have button inside activity_row2
inflated row items.
dataadapter = new simplecursoradapter( this, r.layout.activity_row2, projectscursor, from, to, 0);
you have defined customadapter
never use it.
string[] = new string[]{ginfydbadapter.category_column_title,ginfydbadapter.category_column_content,ginfydbadapter.category_column_count}; // , array of fields want bind fields (in case text1) int[] = new int[]{r.id.text2,r.id.text1,r.id.count}; dataadapter = new customadapter (yourprayeractivity .this, r.layout.activity_row2, projectscursor, from, to);
also change customadapter below
class customadapter extends simplecursoradapter { private layoutinflater minflater; @suppresswarnings("deprecation") public customadapter(context context, int layout, cursor c, string[] from, int[] to) { super(context, layout, c, from, to); minflater= layoutinflater.from(context); toast.maketext(yourprayeractivity.this, "text", 1000).show(); // todo auto-generated constructor stub } @override public void bindview(view view, context context, final cursor cursor){ int row_id = cursor.getcolumnindex("_id"); //your row id (might need replace) textview tv = (textview) view.findviewbyid(r.id.text1); final textview tv1 = (textview) view.findviewbyid(r.id.text2); int col1 = cursor.getcolumnindex("title"); string title = cursor.getstring(col1 ); int col2 = cursor.getcolumnindex("content"); final string content = cursor.getstring(col2 ); tv.settext( title); tv1.settext( content); button button = (button) view.findviewbyid(r.id.buttonsms); button.setonclicklistener(new onclicklistener(){ @override public void onclick(view v){ log.i("....................",""+cursor.getcount()); toast.maketext(yourprayeractivity.this, "text",400000).show(); } }); } @override public view newview(context context, cursor cursor, viewgroup parent){ layoutinflater inflater = layoutinflater.from(context); view v = inflater.inflate(r.layout.activity_row2, parent, false); bindview(v,context,cursor); return v; } }
Comments
Post a Comment