How to return a specific method on button click event?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
Two buttons should update the value "PACK_LIB" inside "Stickers.java".
When they overwrite the String, the method setDefaultStickerPack() should be restarted.
When clicking on buttons b1 or b2 the value "PACK_LIB" will be overwritten by the value "allstickers" or "teststickers".
How can the button b1 or b2 restart the method "if(in==null) "inside setDefaultStickerPack() ?
-------KeyboardService.java
final Button button2 = (Button) mainBoard.findViewById(R.id.b2);
button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Stickers.PACK_LIB = "allstickers";
stickers.setDefaultStickerPack();
showStickers();
}
});
final Button button3 = (Button) mainBoard.findViewById(R.id.b3);
button3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Stickers.PACK_LIB = "teststickers";
stickers.setDefaultStickerPack();
showStickers();
}
});
-------Stickers.java
public static String PACK_LIB ="";
public void setDefaultStickerPack() {
checkVersion(true);
InputStream in = null;
String packList=new String[0];
String PACK_APP="pack_app";
String PACK_ICON="pack_on.png";
String curAssets="";
try {
in = lContext.getAssets().open(PACK_APP+"/"+PACK_ICON);
curAssets=PACK_APP;
packList = lContext.getAssets().list(curAssets);
} catch (IOException e) {
e.printStackTrace();
}
if(in==null) {
try {
in = lContext.getAssets().open(PACK_LIB+"/"+PACK_ICON);
curAssets=PACK_LIB;
packList = lContext.getAssets().list(curAssets);
} catch (IOException e) {
e.printStackTrace();
}
}
if (in != null) {
long packId = 1;
PackData packData = new PackData();
packData.objectId = packId;
packData.name = "ROKOmoji";
packData.iconOn = copyImgFile(in, "i" + packId + "_on");
//packData.iconOff = copyImgFile(inOff, "i" + packId + "_off");
List<StickerData> stickerData = new ArrayList<StickerData>();
long i = 0;
for (String img: packList) {
if(PACK_ICON.equals(img)){
continue;
}
InputStream sIs = null;
try {
sIs = lContext.getAssets().open(curAssets+"/"+img);
} catch (IOException e) {
e.printStackTrace();
}
if (sIs != null) {
StickerData sd = new StickerData();
i=i+1;
File file = copyImgFile(sIs, "s" + img);
sd.objectId = i;
sd.imageId = i;
sd.packId = packId;
sd.packName = packData.name;
sd.file = file;
sd.iconKey = createIconKey(file, "si" + img);
sd.mime = getMimeTypeOfFile(file.getPath());//"image/gif"
sd.url = null;
stickerData.add(sd);
}
}
packData.stickers = stickerData;
packDataListDefault.add(packData);
}
}
java android android-studio button methods
add a comment |
Two buttons should update the value "PACK_LIB" inside "Stickers.java".
When they overwrite the String, the method setDefaultStickerPack() should be restarted.
When clicking on buttons b1 or b2 the value "PACK_LIB" will be overwritten by the value "allstickers" or "teststickers".
How can the button b1 or b2 restart the method "if(in==null) "inside setDefaultStickerPack() ?
-------KeyboardService.java
final Button button2 = (Button) mainBoard.findViewById(R.id.b2);
button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Stickers.PACK_LIB = "allstickers";
stickers.setDefaultStickerPack();
showStickers();
}
});
final Button button3 = (Button) mainBoard.findViewById(R.id.b3);
button3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Stickers.PACK_LIB = "teststickers";
stickers.setDefaultStickerPack();
showStickers();
}
});
-------Stickers.java
public static String PACK_LIB ="";
public void setDefaultStickerPack() {
checkVersion(true);
InputStream in = null;
String packList=new String[0];
String PACK_APP="pack_app";
String PACK_ICON="pack_on.png";
String curAssets="";
try {
in = lContext.getAssets().open(PACK_APP+"/"+PACK_ICON);
curAssets=PACK_APP;
packList = lContext.getAssets().list(curAssets);
} catch (IOException e) {
e.printStackTrace();
}
if(in==null) {
try {
in = lContext.getAssets().open(PACK_LIB+"/"+PACK_ICON);
curAssets=PACK_LIB;
packList = lContext.getAssets().list(curAssets);
} catch (IOException e) {
e.printStackTrace();
}
}
if (in != null) {
long packId = 1;
PackData packData = new PackData();
packData.objectId = packId;
packData.name = "ROKOmoji";
packData.iconOn = copyImgFile(in, "i" + packId + "_on");
//packData.iconOff = copyImgFile(inOff, "i" + packId + "_off");
List<StickerData> stickerData = new ArrayList<StickerData>();
long i = 0;
for (String img: packList) {
if(PACK_ICON.equals(img)){
continue;
}
InputStream sIs = null;
try {
sIs = lContext.getAssets().open(curAssets+"/"+img);
} catch (IOException e) {
e.printStackTrace();
}
if (sIs != null) {
StickerData sd = new StickerData();
i=i+1;
File file = copyImgFile(sIs, "s" + img);
sd.objectId = i;
sd.imageId = i;
sd.packId = packId;
sd.packName = packData.name;
sd.file = file;
sd.iconKey = createIconKey(file, "si" + img);
sd.mime = getMimeTypeOfFile(file.getPath());//"image/gif"
sd.url = null;
stickerData.add(sd);
}
}
packData.stickers = stickerData;
packDataListDefault.add(packData);
}
}
java android android-studio button methods
Whats going wrong with your existing code?
– okcomputer_kid
Jan 3 at 10:23
"allstickers" includes 20 stickers and "teststickers" only 5 . When I click on the button "teststickers" the 5 stickers are shown under the 20 Stickers of "allstickers". And the 20 Stickers are invisible. So i need to scroll down to see the 5 stickers. @okcomputer_kid
– AM13
Jan 3 at 10:26
Try making setDefaultStickerPack() as static and call Stickers.setDefaultStickerPack() rather than creating an instance stickers. ( I am not sure if this will help, I didn't understand completely)
– okcomputer_kid
Jan 3 at 10:29
How do I make setDefaultStickerPack() Static? because when I overwrite inside the code it says "Modifier not allowed here" @okcomputer_kid
– AM13
Jan 3 at 10:37
add a comment |
Two buttons should update the value "PACK_LIB" inside "Stickers.java".
When they overwrite the String, the method setDefaultStickerPack() should be restarted.
When clicking on buttons b1 or b2 the value "PACK_LIB" will be overwritten by the value "allstickers" or "teststickers".
How can the button b1 or b2 restart the method "if(in==null) "inside setDefaultStickerPack() ?
-------KeyboardService.java
final Button button2 = (Button) mainBoard.findViewById(R.id.b2);
button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Stickers.PACK_LIB = "allstickers";
stickers.setDefaultStickerPack();
showStickers();
}
});
final Button button3 = (Button) mainBoard.findViewById(R.id.b3);
button3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Stickers.PACK_LIB = "teststickers";
stickers.setDefaultStickerPack();
showStickers();
}
});
-------Stickers.java
public static String PACK_LIB ="";
public void setDefaultStickerPack() {
checkVersion(true);
InputStream in = null;
String packList=new String[0];
String PACK_APP="pack_app";
String PACK_ICON="pack_on.png";
String curAssets="";
try {
in = lContext.getAssets().open(PACK_APP+"/"+PACK_ICON);
curAssets=PACK_APP;
packList = lContext.getAssets().list(curAssets);
} catch (IOException e) {
e.printStackTrace();
}
if(in==null) {
try {
in = lContext.getAssets().open(PACK_LIB+"/"+PACK_ICON);
curAssets=PACK_LIB;
packList = lContext.getAssets().list(curAssets);
} catch (IOException e) {
e.printStackTrace();
}
}
if (in != null) {
long packId = 1;
PackData packData = new PackData();
packData.objectId = packId;
packData.name = "ROKOmoji";
packData.iconOn = copyImgFile(in, "i" + packId + "_on");
//packData.iconOff = copyImgFile(inOff, "i" + packId + "_off");
List<StickerData> stickerData = new ArrayList<StickerData>();
long i = 0;
for (String img: packList) {
if(PACK_ICON.equals(img)){
continue;
}
InputStream sIs = null;
try {
sIs = lContext.getAssets().open(curAssets+"/"+img);
} catch (IOException e) {
e.printStackTrace();
}
if (sIs != null) {
StickerData sd = new StickerData();
i=i+1;
File file = copyImgFile(sIs, "s" + img);
sd.objectId = i;
sd.imageId = i;
sd.packId = packId;
sd.packName = packData.name;
sd.file = file;
sd.iconKey = createIconKey(file, "si" + img);
sd.mime = getMimeTypeOfFile(file.getPath());//"image/gif"
sd.url = null;
stickerData.add(sd);
}
}
packData.stickers = stickerData;
packDataListDefault.add(packData);
}
}
java android android-studio button methods
Two buttons should update the value "PACK_LIB" inside "Stickers.java".
When they overwrite the String, the method setDefaultStickerPack() should be restarted.
When clicking on buttons b1 or b2 the value "PACK_LIB" will be overwritten by the value "allstickers" or "teststickers".
How can the button b1 or b2 restart the method "if(in==null) "inside setDefaultStickerPack() ?
-------KeyboardService.java
final Button button2 = (Button) mainBoard.findViewById(R.id.b2);
button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Stickers.PACK_LIB = "allstickers";
stickers.setDefaultStickerPack();
showStickers();
}
});
final Button button3 = (Button) mainBoard.findViewById(R.id.b3);
button3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Stickers.PACK_LIB = "teststickers";
stickers.setDefaultStickerPack();
showStickers();
}
});
-------Stickers.java
public static String PACK_LIB ="";
public void setDefaultStickerPack() {
checkVersion(true);
InputStream in = null;
String packList=new String[0];
String PACK_APP="pack_app";
String PACK_ICON="pack_on.png";
String curAssets="";
try {
in = lContext.getAssets().open(PACK_APP+"/"+PACK_ICON);
curAssets=PACK_APP;
packList = lContext.getAssets().list(curAssets);
} catch (IOException e) {
e.printStackTrace();
}
if(in==null) {
try {
in = lContext.getAssets().open(PACK_LIB+"/"+PACK_ICON);
curAssets=PACK_LIB;
packList = lContext.getAssets().list(curAssets);
} catch (IOException e) {
e.printStackTrace();
}
}
if (in != null) {
long packId = 1;
PackData packData = new PackData();
packData.objectId = packId;
packData.name = "ROKOmoji";
packData.iconOn = copyImgFile(in, "i" + packId + "_on");
//packData.iconOff = copyImgFile(inOff, "i" + packId + "_off");
List<StickerData> stickerData = new ArrayList<StickerData>();
long i = 0;
for (String img: packList) {
if(PACK_ICON.equals(img)){
continue;
}
InputStream sIs = null;
try {
sIs = lContext.getAssets().open(curAssets+"/"+img);
} catch (IOException e) {
e.printStackTrace();
}
if (sIs != null) {
StickerData sd = new StickerData();
i=i+1;
File file = copyImgFile(sIs, "s" + img);
sd.objectId = i;
sd.imageId = i;
sd.packId = packId;
sd.packName = packData.name;
sd.file = file;
sd.iconKey = createIconKey(file, "si" + img);
sd.mime = getMimeTypeOfFile(file.getPath());//"image/gif"
sd.url = null;
stickerData.add(sd);
}
}
packData.stickers = stickerData;
packDataListDefault.add(packData);
}
}
java android android-studio button methods
java android android-studio button methods
edited Jan 3 at 11:07
Mahendra Gohil
102111
102111
asked Jan 3 at 10:18
AM13AM13
74
74
Whats going wrong with your existing code?
– okcomputer_kid
Jan 3 at 10:23
"allstickers" includes 20 stickers and "teststickers" only 5 . When I click on the button "teststickers" the 5 stickers are shown under the 20 Stickers of "allstickers". And the 20 Stickers are invisible. So i need to scroll down to see the 5 stickers. @okcomputer_kid
– AM13
Jan 3 at 10:26
Try making setDefaultStickerPack() as static and call Stickers.setDefaultStickerPack() rather than creating an instance stickers. ( I am not sure if this will help, I didn't understand completely)
– okcomputer_kid
Jan 3 at 10:29
How do I make setDefaultStickerPack() Static? because when I overwrite inside the code it says "Modifier not allowed here" @okcomputer_kid
– AM13
Jan 3 at 10:37
add a comment |
Whats going wrong with your existing code?
– okcomputer_kid
Jan 3 at 10:23
"allstickers" includes 20 stickers and "teststickers" only 5 . When I click on the button "teststickers" the 5 stickers are shown under the 20 Stickers of "allstickers". And the 20 Stickers are invisible. So i need to scroll down to see the 5 stickers. @okcomputer_kid
– AM13
Jan 3 at 10:26
Try making setDefaultStickerPack() as static and call Stickers.setDefaultStickerPack() rather than creating an instance stickers. ( I am not sure if this will help, I didn't understand completely)
– okcomputer_kid
Jan 3 at 10:29
How do I make setDefaultStickerPack() Static? because when I overwrite inside the code it says "Modifier not allowed here" @okcomputer_kid
– AM13
Jan 3 at 10:37
Whats going wrong with your existing code?
– okcomputer_kid
Jan 3 at 10:23
Whats going wrong with your existing code?
– okcomputer_kid
Jan 3 at 10:23
"allstickers" includes 20 stickers and "teststickers" only 5 . When I click on the button "teststickers" the 5 stickers are shown under the 20 Stickers of "allstickers". And the 20 Stickers are invisible. So i need to scroll down to see the 5 stickers. @okcomputer_kid
– AM13
Jan 3 at 10:26
"allstickers" includes 20 stickers and "teststickers" only 5 . When I click on the button "teststickers" the 5 stickers are shown under the 20 Stickers of "allstickers". And the 20 Stickers are invisible. So i need to scroll down to see the 5 stickers. @okcomputer_kid
– AM13
Jan 3 at 10:26
Try making setDefaultStickerPack() as static and call Stickers.setDefaultStickerPack() rather than creating an instance stickers. ( I am not sure if this will help, I didn't understand completely)
– okcomputer_kid
Jan 3 at 10:29
Try making setDefaultStickerPack() as static and call Stickers.setDefaultStickerPack() rather than creating an instance stickers. ( I am not sure if this will help, I didn't understand completely)
– okcomputer_kid
Jan 3 at 10:29
How do I make setDefaultStickerPack() Static? because when I overwrite inside the code it says "Modifier not allowed here" @okcomputer_kid
– AM13
Jan 3 at 10:37
How do I make setDefaultStickerPack() Static? because when I overwrite inside the code it says "Modifier not allowed here" @okcomputer_kid
– AM13
Jan 3 at 10:37
add a comment |
1 Answer
1
active
oldest
votes
U can call the method with parameter. try with this.
-------KeyboardService.java
final Button button2 = (Button) mainBoard.findViewById(R.id.b2);
button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
stickers.setDefaultStickerPack("allstickers");
showStickers();
}
});
final Button button3 = (Button) mainBoard.findViewById(R.id.b3);
button3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
stickers.setDefaultStickerPack("teststickers");
showStickers();
}
});
-------Stickers.java
private static String PACK_LIB ="";
public void setDefaultStickerPack(String packLibValue) {
checkVersion(true);
InputStream in = null;
String packList=new String[0];
String PACK_APP="pack_app";
String PACK_ICON="pack_on.png";
String curAssets="";
PACK_LIB = packLibValue
try {
in = lContext.getAssets().open(PACK_APP+"/"+PACK_ICON);
curAssets=PACK_APP;
packList = lContext.getAssets().list(curAssets);
} catch (IOException e) {
e.printStackTrace();
}
if(in==null) {
try {
in = lContext.getAssets().open(PACK_LIB+"/"+PACK_ICON);
curAssets=PACK_LIB;
packList = lContext.getAssets().list(curAssets);
} catch (IOException e) {
e.printStackTrace();
}
}
..........
..........
}
I tried it, but with the same result. I found out that when I close and launch the app again that it works. But can I restart the app when pressing a button? @M.S.T
– AM13
Jan 3 at 19:44
yes definitely u can restart app during button click, just write this method and call it on button click @Override protected void onRestart() { super.onRestart(); } ---- onRestart(); stickers.setDefaultStickerPack("allstickers"); showStickers(); but it would be bad coding, U can try with another way like add below line on ur AndroidManifest file android:alwaysRetainTaskState="false"
– M.S.T
Jan 4 at 8:09
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54020282%2fhow-to-return-a-specific-method-on-button-click-event%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
U can call the method with parameter. try with this.
-------KeyboardService.java
final Button button2 = (Button) mainBoard.findViewById(R.id.b2);
button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
stickers.setDefaultStickerPack("allstickers");
showStickers();
}
});
final Button button3 = (Button) mainBoard.findViewById(R.id.b3);
button3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
stickers.setDefaultStickerPack("teststickers");
showStickers();
}
});
-------Stickers.java
private static String PACK_LIB ="";
public void setDefaultStickerPack(String packLibValue) {
checkVersion(true);
InputStream in = null;
String packList=new String[0];
String PACK_APP="pack_app";
String PACK_ICON="pack_on.png";
String curAssets="";
PACK_LIB = packLibValue
try {
in = lContext.getAssets().open(PACK_APP+"/"+PACK_ICON);
curAssets=PACK_APP;
packList = lContext.getAssets().list(curAssets);
} catch (IOException e) {
e.printStackTrace();
}
if(in==null) {
try {
in = lContext.getAssets().open(PACK_LIB+"/"+PACK_ICON);
curAssets=PACK_LIB;
packList = lContext.getAssets().list(curAssets);
} catch (IOException e) {
e.printStackTrace();
}
}
..........
..........
}
I tried it, but with the same result. I found out that when I close and launch the app again that it works. But can I restart the app when pressing a button? @M.S.T
– AM13
Jan 3 at 19:44
yes definitely u can restart app during button click, just write this method and call it on button click @Override protected void onRestart() { super.onRestart(); } ---- onRestart(); stickers.setDefaultStickerPack("allstickers"); showStickers(); but it would be bad coding, U can try with another way like add below line on ur AndroidManifest file android:alwaysRetainTaskState="false"
– M.S.T
Jan 4 at 8:09
add a comment |
U can call the method with parameter. try with this.
-------KeyboardService.java
final Button button2 = (Button) mainBoard.findViewById(R.id.b2);
button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
stickers.setDefaultStickerPack("allstickers");
showStickers();
}
});
final Button button3 = (Button) mainBoard.findViewById(R.id.b3);
button3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
stickers.setDefaultStickerPack("teststickers");
showStickers();
}
});
-------Stickers.java
private static String PACK_LIB ="";
public void setDefaultStickerPack(String packLibValue) {
checkVersion(true);
InputStream in = null;
String packList=new String[0];
String PACK_APP="pack_app";
String PACK_ICON="pack_on.png";
String curAssets="";
PACK_LIB = packLibValue
try {
in = lContext.getAssets().open(PACK_APP+"/"+PACK_ICON);
curAssets=PACK_APP;
packList = lContext.getAssets().list(curAssets);
} catch (IOException e) {
e.printStackTrace();
}
if(in==null) {
try {
in = lContext.getAssets().open(PACK_LIB+"/"+PACK_ICON);
curAssets=PACK_LIB;
packList = lContext.getAssets().list(curAssets);
} catch (IOException e) {
e.printStackTrace();
}
}
..........
..........
}
I tried it, but with the same result. I found out that when I close and launch the app again that it works. But can I restart the app when pressing a button? @M.S.T
– AM13
Jan 3 at 19:44
yes definitely u can restart app during button click, just write this method and call it on button click @Override protected void onRestart() { super.onRestart(); } ---- onRestart(); stickers.setDefaultStickerPack("allstickers"); showStickers(); but it would be bad coding, U can try with another way like add below line on ur AndroidManifest file android:alwaysRetainTaskState="false"
– M.S.T
Jan 4 at 8:09
add a comment |
U can call the method with parameter. try with this.
-------KeyboardService.java
final Button button2 = (Button) mainBoard.findViewById(R.id.b2);
button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
stickers.setDefaultStickerPack("allstickers");
showStickers();
}
});
final Button button3 = (Button) mainBoard.findViewById(R.id.b3);
button3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
stickers.setDefaultStickerPack("teststickers");
showStickers();
}
});
-------Stickers.java
private static String PACK_LIB ="";
public void setDefaultStickerPack(String packLibValue) {
checkVersion(true);
InputStream in = null;
String packList=new String[0];
String PACK_APP="pack_app";
String PACK_ICON="pack_on.png";
String curAssets="";
PACK_LIB = packLibValue
try {
in = lContext.getAssets().open(PACK_APP+"/"+PACK_ICON);
curAssets=PACK_APP;
packList = lContext.getAssets().list(curAssets);
} catch (IOException e) {
e.printStackTrace();
}
if(in==null) {
try {
in = lContext.getAssets().open(PACK_LIB+"/"+PACK_ICON);
curAssets=PACK_LIB;
packList = lContext.getAssets().list(curAssets);
} catch (IOException e) {
e.printStackTrace();
}
}
..........
..........
}
U can call the method with parameter. try with this.
-------KeyboardService.java
final Button button2 = (Button) mainBoard.findViewById(R.id.b2);
button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
stickers.setDefaultStickerPack("allstickers");
showStickers();
}
});
final Button button3 = (Button) mainBoard.findViewById(R.id.b3);
button3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
stickers.setDefaultStickerPack("teststickers");
showStickers();
}
});
-------Stickers.java
private static String PACK_LIB ="";
public void setDefaultStickerPack(String packLibValue) {
checkVersion(true);
InputStream in = null;
String packList=new String[0];
String PACK_APP="pack_app";
String PACK_ICON="pack_on.png";
String curAssets="";
PACK_LIB = packLibValue
try {
in = lContext.getAssets().open(PACK_APP+"/"+PACK_ICON);
curAssets=PACK_APP;
packList = lContext.getAssets().list(curAssets);
} catch (IOException e) {
e.printStackTrace();
}
if(in==null) {
try {
in = lContext.getAssets().open(PACK_LIB+"/"+PACK_ICON);
curAssets=PACK_LIB;
packList = lContext.getAssets().list(curAssets);
} catch (IOException e) {
e.printStackTrace();
}
}
..........
..........
}
edited Jan 3 at 12:54
answered Jan 3 at 12:39
M.S.TM.S.T
588
588
I tried it, but with the same result. I found out that when I close and launch the app again that it works. But can I restart the app when pressing a button? @M.S.T
– AM13
Jan 3 at 19:44
yes definitely u can restart app during button click, just write this method and call it on button click @Override protected void onRestart() { super.onRestart(); } ---- onRestart(); stickers.setDefaultStickerPack("allstickers"); showStickers(); but it would be bad coding, U can try with another way like add below line on ur AndroidManifest file android:alwaysRetainTaskState="false"
– M.S.T
Jan 4 at 8:09
add a comment |
I tried it, but with the same result. I found out that when I close and launch the app again that it works. But can I restart the app when pressing a button? @M.S.T
– AM13
Jan 3 at 19:44
yes definitely u can restart app during button click, just write this method and call it on button click @Override protected void onRestart() { super.onRestart(); } ---- onRestart(); stickers.setDefaultStickerPack("allstickers"); showStickers(); but it would be bad coding, U can try with another way like add below line on ur AndroidManifest file android:alwaysRetainTaskState="false"
– M.S.T
Jan 4 at 8:09
I tried it, but with the same result. I found out that when I close and launch the app again that it works. But can I restart the app when pressing a button? @M.S.T
– AM13
Jan 3 at 19:44
I tried it, but with the same result. I found out that when I close and launch the app again that it works. But can I restart the app when pressing a button? @M.S.T
– AM13
Jan 3 at 19:44
yes definitely u can restart app during button click, just write this method and call it on button click @Override protected void onRestart() { super.onRestart(); } ---- onRestart(); stickers.setDefaultStickerPack("allstickers"); showStickers(); but it would be bad coding, U can try with another way like add below line on ur AndroidManifest file android:alwaysRetainTaskState="false"
– M.S.T
Jan 4 at 8:09
yes definitely u can restart app during button click, just write this method and call it on button click @Override protected void onRestart() { super.onRestart(); } ---- onRestart(); stickers.setDefaultStickerPack("allstickers"); showStickers(); but it would be bad coding, U can try with another way like add below line on ur AndroidManifest file android:alwaysRetainTaskState="false"
– M.S.T
Jan 4 at 8:09
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54020282%2fhow-to-return-a-specific-method-on-button-click-event%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Whats going wrong with your existing code?
– okcomputer_kid
Jan 3 at 10:23
"allstickers" includes 20 stickers and "teststickers" only 5 . When I click on the button "teststickers" the 5 stickers are shown under the 20 Stickers of "allstickers". And the 20 Stickers are invisible. So i need to scroll down to see the 5 stickers. @okcomputer_kid
– AM13
Jan 3 at 10:26
Try making setDefaultStickerPack() as static and call Stickers.setDefaultStickerPack() rather than creating an instance stickers. ( I am not sure if this will help, I didn't understand completely)
– okcomputer_kid
Jan 3 at 10:29
How do I make setDefaultStickerPack() Static? because when I overwrite inside the code it says "Modifier not allowed here" @okcomputer_kid
– AM13
Jan 3 at 10:37