i have made variable tweet inside first onclick event. need variable onclick event. either variable tweet or variable randomindex. i'm searching internet 2 hours now, having problems find how can pass variable. understand when onclick event finishes, kills variable.
buttonwhattodonow.setonclicklistener(new view.onclicklistener() { public int getrandomnumber(int max) { random rand = new random(); int num = rand.nextint(max); return num; } int randomindex; public void onclick(view v) { int countmax = databasehelper.getcountnow(); randomindex = getrandomnumber(countmax) + 1; string boolean = databasehelper.getboolean(randomindex); if (boolean == "1") { randomindex = getrandomnumber(countmax) + 1; boolean = databasehelper.getboolean(randomindex); } while (boolean == "1") { randomindex = getrandomnumber(countmax) + 1; boolean = databasehelper.getboolean(randomindex); } string title = databasehelper.gettitlenow(randomindex); string text1 = databasehelper.gettext1now(randomindex); string text2 = databasehelper.gettext2now(randomindex); string text3 = databasehelper.gettext3now(randomindex); string tweet = databasehelper.gettweetnow(randomindex); string image1 = databasehelper.getimage1now(randomindex); string image2 = databasehelper.getimage2now(randomindex); string image3 = databasehelper.getimage3now(randomindex); textviewdothistitle.settext(title); textviewdothistext1.settext(text1); imageviewdothis1.setimageresource(getresources().getidentifier( image1, "drawable", getpackagename())); textviewdothistext2.settext(text2); imageviewdothis2.setimageresource(getresources().getidentifier( image2, "drawable", getpackagename())); textviewdothistext3.settext(text3); imageviewdothis3.setimageresource(getresources().getidentifier( image3, "drawable", getpackagename())); } public final int asddd = randomindex; }); buttontweetthis.setonclicklistener(new view.onclicklistener() { @override public void onclick(view arg0) { // todo auto-generated method stub intent sendintent = new intent(intent.action_send); sendintent.putextra(intent.extra_text, tweet); sendintent.settype("application/twitter"); startactivity(intent.createchooser(sendintent, null)); } });
i dont know why dont use class variable anyway can try this:
settag(object tag) //sets tag associated view. gettag(object tag) //gets tag associated view. place want save example view.settag(tweet); in other onclick yo can raw object , have cast want. using view.gettag();
Comments
Post a Comment