Sliding image 4x4 with GridLayout - android

I want ask about sliding image puzzle.
below is code for slide to left or right.
but I have a problem.
if (i + 1 < imageviews.size) {
if (imageviews[i + 1]!!.drawable == null) {
mGridLayout.removeView(imageviews[i + 1])
mGridLayout.addView(imageviews[i + 1], i)
val temp = imageviews[i + 1]
imageviews[i + 1] = imageviews[i]
imageviews[i] = temp
}
}
if (i - 1 >= 0) {
if (imageviews[i - 1]!!.drawable == null) {
mGridLayout.removeView(imageviews[i - 1])
mGridLayout.addView(imageviews[i - 1], i)
val temp = imageviews[i - 1]
imageviews[i - 1] = imageviews[i]
imageviews[i] = temp
}
}
before do anything:

I have updated setOnClickListener() function and it seems to be working but I haven't solved it completely:
private fun setOnClickListener() {
Log.i(TAG, "${imageviews.size} ")
for (i in 0 until imageviews.size step 1) {
imageviews[i]!!.setOnClickListener {
Log.i(TAG, "${imageviews.size} $i")
val top: Int? = if (i - GRID_NO >= 0) i - GRID_NO else null
val bottom: Int? = if (i + GRID_NO < imageviews.size) i + GRID_NO else null
val left: Int? = if (i % GRID_NO > 0) i - 1 else null
val right: Int? = if (i % GRID_NO < GRID_NO - 1) i + 1 else null
// Log.i(TAG, "Top: $top Bottom: $bottom Left: $left Right: $right")
if (top != null && imageviews[top]!!.drawable == null) {
imageviews[top]!!.setImageDrawable(imageviews[i]!!.drawable)
mGridLayout.removeViewAt(i)
mGridLayout.addView(imageviews[i], i)
imageviews[i]!!.setImageDrawable(null)
} else if (bottom != null && imageviews[bottom]!!.drawable == null) {
imageviews[bottom]!!.setImageDrawable(imageviews[i]!!.drawable)
mGridLayout.removeViewAt(i)
mGridLayout.addView(imageviews[i], i)
imageviews[i]!!.setImageDrawable(null)
} else if (left != null && imageviews[left]!!.drawable == null) {
imageviews[left]!!.setImageDrawable(imageviews[i]!!.drawable)
mGridLayout.removeViewAt(i)
mGridLayout.addView(imageviews[i], i)
imageviews[i]!!.setImageDrawable(null)
} else if (right != null && imageviews[right]!!.drawable == null) {
imageviews[right]!!.setImageDrawable(imageviews[i]!!.drawable)
mGridLayout.removeViewAt(i)
mGridLayout.addView(imageviews[i], i)
imageviews[i]!!.setImageDrawable(null)
}
if (isSolved()) {
Toast.makeText(this, "Success , true", Toast.LENGTH_SHORT).show()
}
}
}
}
UPDATED isSolved() FUNCTION UPON REQUEST
Updated isSolved() looks like as follows:
private fun isSolved(): Boolean {
var solved = true
for (i in 0 until GRID_NO) {
for (j in 0 until GRID_NO) {
val index: Int = i * GRID_NO + j
if (imageviews[index]!!.drawable == null) {
continue
} else if (imageviews[index]!!.drawable != imageViews[i][j]!!.drawable) {
solved = false
break
}
}
}
return solved
}
Please note that this version returns true if all cells except the empty cell in correct place, meaning that empty cell can be any cell at the end. If these kind of puzzles normally have more restricted success rules, like the empty cell should be on the corners, it needs to be updated.

Related

Remove Unknown tags (C3, BF40, C2) from TLV using TLVUtility on terminalSdk-2.0.3.jar

I am trying to remove some Unknown tags (C3, BF40, C2,.. etc) from ByteArray using TLVUtility (mastercard class from terminalSdk-2.0.3.jar), Tags was not removing from the ByteArray. I am trying like this,
Here is my TLV Data I have,
ppseResponse = ByteUtility.hexStringToByteArray("6F54840E325041592E5359532E4444463031C30F4920414D2054484520424553542033BF4003C20101A52BBF0C28610C4F07A0000000041010870101610C4F07A0000000043060870103610A4F05B0123456788701099000")
I am trying this to remove the Unknown tags like,
"BEFORE << ${ByteUtility.byteArrayToHexString(ppseResponse)}".toLog(activity, TAG) //To print Log
val unknownTags = byteArrayOf((0x00C3).toByte(),(0xBF40).toByte(), (0x00C2).toByte())
var removed = TLVUtility.removeTag(ppseResponse, ContentType.TLV,unknownTags)
"AFTER << ${ByteUtility.byteArrayToHexString(removed)}".toLog(activity, TAG) //To print Log
Here is the function removeTag on terminalSdk-2.0.3.jar function look likes,
public static byte[] removeTag(byte[] var0, ContentType var1, byte[] var2) {
int var10000;
Throwable var10001;
String var28;
label698: {
var10000 = 2 % 2;
if (var0 != null) {
label691: {
var10000 = g + 85;
f = var10000 % 128;
if (var10000 % 2 == 0) {
byte[] var26 = var2;
byte var27;
label676: {
label675: {
try {
null.hashCode();
if (var26 == null) {
break label675;
}
} catch (Throwable var25) {
throw var25;
}
var27 = 42;
break label676;
}
var27 = 74;
}
switch(var27) {
case 42:
break;
case 74:
default:
break label691;
}
} else if (var2 == null) {
break label691;
}
var10000 = f + 55;
g = var10000 % 128;
switch(var10000 % 2 != 0 ? 0 : 1) {
case 0:
default:
if (var2.length >= 1) {
break label698;
}
break;
case 1:
if (var2.length >= 1) {
break label698;
}
}
}
}
var28 = e(31, '卆', 490).intern();
try {
((Class)q.b(38, 8595, '\ue0f7')).getMethod("e", String.class).invoke((Object)null, var28);
} catch (Throwable var22) {
var10001 = var22.getCause();
if (var10001 != null) {
throw var10001;
}
throw var22;
}
throw new LibraryUncheckedException(ExceptionCode.X6F44);
}
label700: {
if (var1 == ContentType.T) {
var10000 = g + 15;
f = var10000 % 128;
if (var10000 % 2 == 0) {
if (var0.length < 0) {
break label700;
}
} else if (var0.length < 1) {
break label700;
}
}
switch(var1 != ContentType.TLV ? 81 : 64) {
case 81:
if (var1 != ContentType.TDO) {
break;
}
case 64:
default:
if (var0.length < 3) {
var28 = e(47, '\u0000', 560).intern();
try {
((Class)q.b(38, 8595, '\ue0f7')).getMethod("e", String.class).invoke((Object)null, var28);
} catch (Throwable var23) {
var10001 = var23.getCause();
if (var10001 != null) {
throw var10001;
}
throw var23;
}
throw new LibraryUncheckedException(ExceptionCode.X6F43);
}
}
ArrayList var3 = conditionalTlvParsing(var0, var1, e(1, '\u0000', 140).intern(), true);
Iterator var4 = var3.iterator();
while(var4.hasNext()) {
BerTlv var5 = (BerTlv)var4.next();
switch(var5.getTagObject().getNTag() == ByteUtility.byteArrayToInt(var2) ? 39 : 84) {
case 39:
default:
var4.remove();
case 84:
}
}
return formByteArrayFromTlvList(var3, var1);
}
var28 = e(39, '\u0000', 521).intern();
try {
((Class)q.b(38, 8595, '\ue0f7')).getMethod("e", String.class).invoke((Object)null, var28);
} catch (Throwable var24) {
var10001 = var24.getCause();
if (var10001 != null) {
throw var10001;
}
throw var24;
}
throw new LibraryUncheckedException(ExceptionCode.X6F43);
}
I fixed this issue by creating new custom function. Here is the function. Now on this function I am removing all the Unknown Tags and its Skipping all Known Tags and Third party data and Optional Tags Tags
First we need to define optional Tag,
private var optionalTags: ArrayList<ByteArray> = getOptionalTags()
Here is the function I am adding Optional Tags,
private fun getOptionalTags(): ArrayList<ByteArray> {
optionalTags = ArrayList()
optionalTags.add(ByteUtility.hexStringToByteArray("9F3E")) //Terminal Categories Supported List
optionalTags.add(ByteUtility.hexStringToByteArray("9F3F")) //Selection Data Object List
optionalTags.add(ByteUtility.hexStringToByteArray("9F2A")) //Kernel Identifier
optionalTags.add(ByteUtility.hexStringToByteArray("9F0A")) //Application Selection Registered Proprietary Data
return optionalTags
}
Here is the function to remove the Unknown tags,
private fun removeUnknownTags(ppseResponse: ByteArray): ByteArray {
var parentTags: MutableMap<ByteArray, Int> = LinkedHashMap()
var ppseResp = ppseResponse;
var i = 0
"PPSE (Length: ${ppseResp.size}) : HexString: ${ByteUtility.byteArrayToHexString(ppseResp)} \n ByteArray: ${ppseResp.toList()}".toLog()
while (i < ppseResp.size - 1) {
var removeTag = false;
var currentTag = TLVUtility.getCurrentTag(ppseResp, i);
var nextIndex = i + currentTag.size;
var tLVLengthInfo = TLVUtility.getTLVLengthInfo(ppseResp, nextIndex);
val tagLength = tLVLengthInfo.expectedNumberOfBytes
var tagValueSize = tLVLengthInfo.lengthBytes.size
var tagValue = ByteUtility.getSubByteArray(ppseResp, nextIndex + tagValueSize, tagLength)
"<==- ${i} : ${ByteUtility.byteArrayToHexString(currentTag)} (${TLVUtility.getReferenceTagDetails(currentTag).name}) , Length:${tagLength} (${tLVLengthInfo.lengthBytes.toList()} : ${ByteUtility.byteArrayToHexString(tLVLengthInfo.lengthBytes)}) , Max:${TLVUtility.getReferenceTagDetails(currentTag).maxLen} , Min:${TLVUtility.getReferenceTagDetails(currentTag).minLen} -==>".toLog()
"Value : ${ByteUtility.byteArrayToHexString(tagValue)} , Bytes:${tagValue.toList()}".toLog()
var tagNameLengthValue = ByteUtility.getSubByteArray(ppseResp, i, currentTag.size + tagValueSize + tagLength)
if (TLVUtility.getReferenceTagDetails(currentTag).name.contentEquals("Unknown Tag")) {
var optionalTag = false;
for (optTag in optionalTags) {
if (currentTag.contentEquals(optTag)) {
"${ByteUtility.byteArrayToHexString(currentTag)} is Optional Tag".toLog()
i = nextIndex + tagValueSize + tagLength;
optionalTag = true;
break
}
}
if (!optionalTag)
removeTag = true
} else if (TLVUtility.getReferenceTagDetails(currentTag).name.contentEquals("Third Party Data")) {
i = nextIndex + tagValueSize + tagLength;
} else {
if (!removeTag) {
if (TLVUtility.isTLVEncoded(tagValue)) {
parentTags.put(currentTag, i)
parentTags.entries.stream()
.sorted(Map.Entry.comparingByValue<ByteArray, Int>().reversed())
.forEachOrdered { x -> parentTags.put(x.key, x.value) }
if (tagValue.contentEquals(ByteUtility.hexStringToByteArray("00"))) {
i = nextIndex + tagValueSize + tagLength;
} else
i = nextIndex + tagValueSize
} else {
i = nextIndex + tagValueSize + tagLength;
}
}
}
if (removeTag) {
"-*-*-*-Removing TAG ${ByteUtility.byteArrayToHexString(currentTag)}-*-*-*-".toLog()
ppseResp = ByteUtility.getSubByteArray(ppseResp, 0, i) + ByteUtility.getSubByteArray(ppseResp, i + tagNameLengthValue.size)
var byteDiff = tagNameLengthValue.size
"--Updating Tag Length (Removed Bytes ${byteDiff})--".toLog()
for (tag in parentTags.entries.reversed()) {
var parentBytes = tag.key
var index = tag.value
var sizeIndex = index + parentBytes.size
var unknownTLVLengthInfo = TLVUtility.getTLVLengthInfo(ppseResp, sizeIndex);
val length = unknownTLVLengthInfo.expectedNumberOfBytes
if (i > index && i <= index + length) { //To Check is Parent Tag
"Parent Tag ${ByteUtility.byteArrayToHexString(tag.key)} (Bytes:${tag.key.toList()}) , Position:${tag.value}".toLog()
var lengthByteArray = unknownTLVLengthInfo.lengthBytes
var newLengthByteArray = ByteUtility.intToBerEncodedLength(length - byteDiff).bytes
var lengthDiff = lengthByteArray.size - newLengthByteArray.size;
byteDiff = byteDiff + lengthDiff
ppseResp = ByteUtility.getSubByteArray(ppseResp, 0, sizeIndex) + newLengthByteArray + ByteUtility.getSubByteArray(ppseResp, sizeIndex + lengthByteArray.size)
if (lengthDiff > 0) {
i = i - lengthDiff
for (child in parentTags.entries) {
if (child.value > tag.value) {
parentTags.replace(child.key, child.value - lengthDiff)
}
}
}
// "PPSE After (Length: ${ppseResp.size}): ${ByteUtility.byteArrayToHexString(ppseResp)} \n ByteArray: ${ppseResp.toList()}".toLog()
}
}
}
}
return ppseResp;
}

Kotlin if statement only returning the first if not checking else if

The requirements have the two first fun to be in ViewModel. val f and run are in Main Activity. The loop is stopping. I think there might be an issue toFloat(). Is there something that I am missing? Thank you for the help.
val f = bmiViewModel.updatebmi(bmiViewModel.formula(inc, wt, ft))
run(f)
fun formula(inc: Int, ft: Int, wt: Int): Float {
val htTotal = (ft*12).toFloat() + inc.toFloat()
val BMI = (wt.toFloat()*703) / (htTotal * htTotal)
Log.d(TAG,"BMI", Exception())
return BMI
fun updatebmi(total: Float): Int{
if (total < 18.5) {
return -256
} else if (total >= 18.5 && total < 24.9) {
return 8
} else if (total >= 24.9 && total < 30) {
return 256
} else{
return 16
}
}
private fun run(i: Int){
if (i == -256) {
binding.status.text = "Under Weight"
binding.status.setTextColor(i)
} else if (i == 8) {
binding.status.text = "Normal"
binding.status.setTextColor(i)
} else if (i == 256) {
binding.status.text = "Overweight"
binding.status.setTextColor(-256)
} else{
binding.status.text = "Obese"
binding.status.setTextColor(16)
}

Why do I get a gray background for item when i addView for ViewGroup when keep space keylistener?

When i keep key listener for this view
edit_text.setOnKeyListener(keyListener)
Space key code
KeyEvent.KEYCODE_SPACE -> {
if (listener != null && event.action == KeyEvent.ACTION_DOWN) {
val text = edit_text.text
if (text.isEmpty()) {
return#OnKeyListener false
}
val startSelection = edit_text.selectionStart
val endSelection = edit_text.selectionEnd
if (startSelection < 0 || endSelection < 0) {
return#OnKeyListener false
}
if (endSelection == startSelection) {
val urlSpan = text.getSpans(0, startSelection, EditorUrlSpan::class.java)
if (urlSpan?.isNotEmpty() == true) {
val firstUrlSpan = urlSpan[0]
val lastUrlSpan = urlSpan[urlSpan.size - 1]
val firstStartIndex = text.getSpanStart(firstUrlSpan)
val firstEndIndex = text.getSpanEnd(firstUrlSpan)
val lastStartIndex = text.getSpanStart(lastUrlSpan)
val lastEndIndex = text.getSpanEnd(lastUrlSpan)
val character = when {
firstEndIndex < lastStartIndex -> text.subSequence(firstEndIndex, lastStartIndex)
firstStartIndex == lastStartIndex && firstEndIndex == lastEndIndex -> " "
else -> ""
}
when {
firstStartIndex == 0 && lastEndIndex >= endSelection && character == " " -> {
text.delete(lastStartIndex, lastEndIndex)
setText(text)
setSelection(length())
listener?.insertLink(this#KoalaEditTextView, lastUrlSpan.mLinkData.apply {
this.linkTitle = this.linkTitle?.replace("$href ", "")
})
return#OnKeyListener true
}
lastUrlSpan.mLinkData.linkTitle.isNullOrEmpty() -> {
sendParseUrlMessage(lastStartIndex, lastEndIndex, lastUrlSpan.mLinkData.linkUrl)
return#OnKeyListener true
}
}
}
}
}
false
}
End key code
KeyEvent.KEYCODE_ENTER -> {
if (listener != null && event.action == KeyEvent.ACTION_DOWN) {
if (section == SECTION_NULL) {
if (!quote) {
listener!!.pressEnter(this#KoalaEditTextView)
return#OnKeyListener true
} else {
val text = edit_text.text
if (text.isEmpty()) {
setText("")
listener!!.pressEnter(this#KoalaEditTextView)
return#OnKeyListener true
} else if (edit_text.selectionEnd == text.length && text.toString()[text.length - 1] == '\n') {
setText(text.subSequence(0, text.toString().length - 1))
setSelection(edit_text.length())
listener!!.pressEnter(this#KoalaEditTextView)
return#OnKeyListener true
}
if (edit_text.selectionStart == edit_text.selectionEnd && edit_text.selectionStart == 1
&& text.toString()[0] == '\n') {
setText(text.subSequence(1, text.length))
listener!!.insertEdit(this#KoalaEditTextView)
return#OnKeyListener true
}
}
} else {
if (edit_text.text.toString().trim { it <= ' ' }.isEmpty()) {
cleanSection(this#KoalaEditTextView)
resetPosition()
return#OnKeyListener true
} else {
listener!!.pressEnter(this#KoalaEditTextView)
return#OnKeyListener true
}
}
return#OnKeyListener false
}
true
}
and listener insertLink and pressEnter
override fun insertLink(v: KoalaEditTextView, linkData: LinkData) {
val index = container.indexOfChild(v)
val linkView = KoalaLinkView(context, linkData)
linkView.setOnLinkClickListener(itemLinkListener)
val lpCard = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
container.addView(linkView, index + 1, lpCard)
linkView.requestFocus()
linkView.post {
linkView.link_right_area.requestFocus()
linkView.link_right_area.performClick()
}
}
override fun pressEnter(v: KoalaEditTextView) {
var leftSelectionText: CharSequence
var rightSelectionText: CharSequence
val index = container.indexOfChild(v)
val startSelection = v.selectionStart
val endSelection = v.selectionStart
val txt = SpannableStringBuilder(v.obtainText())
if (startSelection < v.length()) {
leftSelectionText = txt.subSequence(0, if (startSelection > -1) {
startSelection
} else {
0
})
rightSelectionText = txt.subSequence(if (startSelection > -1) {
startSelection
} else {
0
}, v.length())
} else {
leftSelectionText = txt
rightSelectionText = ""
}
val urlSpan = txt.getSpans(0, startSelection, KoalaEditTextView.Companion.EditorUrlSpan::class.java)
if (urlSpan?.isNotEmpty() == true) {
val firstUrlSpan = urlSpan[0]
val lastUrlSpan = urlSpan[urlSpan.size - 1]
val firstStartIndex = txt.getSpanStart(firstUrlSpan)
val firstEndIndex = txt.getSpanEnd(firstUrlSpan)
val lastStartIndex = txt.getSpanStart(lastUrlSpan)
val lastEndIndex = txt.getSpanEnd(lastUrlSpan)
val character = when {
firstEndIndex < lastStartIndex -> txt.subSequence(firstEndIndex, lastStartIndex)
firstStartIndex == lastStartIndex && firstEndIndex == lastEndIndex -> "\n"
else -> ""
}
when {
firstStartIndex == 0 && startSelection > 0 && lastEndIndex >= endSelection && character == "\n" -> {
txt.delete(lastStartIndex, lastEndIndex)
v.setText(txt)
v.setSelection(v.length())
insertLink(v, lastUrlSpan.mLinkData.apply {
this.linkTitle = this.linkTitle?.replace("$href ", "")
})
return
}
lastUrlSpan.mLinkData.linkTitle.isNullOrEmpty() -> {
v.sendParseUrlMessage(lastStartIndex, lastEndIndex, lastUrlSpan.mLinkData.linkUrl)
return
}
endSelection > -1 && lastEndIndex > endSelection -> {
leftSelectionText = txt.subSequence(0, lastStartIndex)
rightSelectionText = txt.subSequence(lastStartIndex, v.length())
}
}
}
v.setText(leftSelectionText)
val editTextView = KoalaEditTextView(context, this, menuStatusListener, contentListener)
val lp = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
container.addView(editTextView, index + 1, lp)
editTextView.setText(rightSelectionText)
editTextView.requestFocus()
editTextView.setSelection(0)
if (v.obtainSection() == SECTION_NUMBER) {
editTextView.setNumberSection(editTextView)
} else if (v.obtainSection() == SECTION_DOT) {
editTextView.setDotSection(editTextView)
}
editTextView.resetPosition()
setHint()
}
something has happend when i press space and enter, the code has called
add view for space key
add view for enter key
called the same code, and space key got a gray bg, the enter key is not
the gray background
How to solve this? Thank you!
now, i solved it by look android source code for InputMethodService.class
in my code ,i has implemented InputConnectionWrapper to override commitText for this code
override fun commitText(text: CharSequence?, newCursorPosition: Int): Boolean {
return when {
text?.toString() == "\n" -> sendDownUpKeyEvents(KeyEvent.KEYCODE_ENTER)
text?.toString() == " " -> sendDownUpKeyEvents(KeyEvent.KEYCODE_SPACE)
else -> super.commitText(text, newCursorPosition)
}
}
private fun sendDownUpKeyEvents(keyCode: Int): Boolean {
val eventTime = SystemClock.uptimeMillis()
return sendKeyEvent(KeyEvent(eventTime, eventTime,
KeyEvent.ACTION_DOWN, keyCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0,
KeyEvent.FLAG_SOFT_KEYBOARD or KeyEvent.FLAG_KEEP_TOUCH_MODE))
&& sendKeyEvent(KeyEvent(eventTime, eventTime,
KeyEvent.ACTION_UP, keyCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0,
KeyEvent.FLAG_SOFT_KEYBOARD or KeyEvent.FLAG_KEEP_TOUCH_MODE))
}
something happend in there sendDownUpKeyEvents,this bug is happend where i used
text?.toString() == " " -> sendKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SPACE))
&& sendKeyEvent(KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SPACE))
i read the reasons for KeyEvent.class constructor params in flags
the KeyEvent.FLAG_KEEP_TOUCH_MODE is more important for this bug!

How to set two adapter for AutocompleteTextview with respect to if conditions

i have two adpters in my app with separate listview
one is for user and another one is for groups
i want set the adapter to the textview when the conditon exists like when the user types a token '#' the user adapter should be set and when the user types a token '#' the channel adapter(for populating list of groups) should be set
my adapters:
final ChannelAdapter customadapter1 = new ChannelAdapter(getActivity(), R.layout.all_cahnnel_list_item, joinOtherChannelList);
final UserAdapter customadapter = new UserAdapter(getActivity(), R.layout.all_user_list_item, userArrayList);
inputMessageView = (MultiAutoCompleteTextView) view.findViewById(R.id.message_input);
inputMessageView.setThreshold(0);
inputMessageView.setTokenizer(new MultiAutoCompleteTextView.Tokenizer() {
#Override
public CharSequence terminateToken(CharSequence text) {
int i = text.length();
while (i > 0 && text.charAt(i - 1) == ' ') {
i--;
}
if (i > 0 && text.charAt(i - 1) == ' ') {
return text;
} else {
if (text instanceof Spanned) {
SpannableString sp = new SpannableString(text + " ");
TextUtils.copySpansFrom((Spanned) text, 0, text.length(), Object.class, sp, 0);
return sp;
} else {
return text + " ";
}
}
}
#Override
public int findTokenStart(CharSequence text, int cursor) {
int i = cursor;
while (((i > 0 && text.charAt(i - 1) != '#') && (i > 0 && text.charAt(i - 1) != '#'))) {
i--;
}//Check if token really started with #, else we don't have a valid token
if (text.charAt(i - 1) != '#') {
inputMessageView.setAdapter(customadapter);
return cursor:
} else if (i < 1 || text.charAt(i - 1) != '#') {
inputMessageView.setAdapter(customadapter1);
return cursor;
}
return i;
}
#Override
public int findTokenEnd(CharSequence text, int cursor) {
int i = cursor;
int len = text.length();
while (i < len) {
if (text.charAt(i) == ' ') {
return i;
} else {
i++;
}
}
return len;
}
});
My problem is when i use if condition alone its working for custom adapter one. But when i use if and else if to set both adapter not even single adapter is working i mean its not displaying anything in the text view
Your conditions aren't same.
if (text.charAt(i - 1) != '#') {
inputMessageView.setAdapter(customadapter)
return cursor;
} else if (i < 1 || text.charAt(i - 1) != '#') {
inputMessageView.setAdapter(customadapter2);
return cursor;
}
If , as you said, works on one if conditions then it should work, because else if part doesn't gets executed. Try using logs and try printing the logs.

How to I finish the "continue;" That i putted after the if statement?

I made a statement and if it is true it continues, I want to stop this "continue" and make another statement for example touchdown and touchup.
here is my code
private void updateRunning(float deltaTime) {
List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
int len = touchEvents.size();
for (int i = 0; i < len; i++) {
TouchEvent event = touchEvents.get(i);
if (event.type != TouchEvent.TOUCH_UP)
continue;
world.doodle.DOODLE_Y = 3;
touchPoint.set(event.x, event.y);
guiCam.touchToWorld(touchPoint);
if (OverlapTester.pointInRectangle(pauseBounds, touchPoint)) {
Assets.clicks();
state = GAME_PAUSED;
return;
}
}
world.update(deltaTime, game.getInput().getAccelX());
if (world.score != lastScore) {
lastScore = world.score;
scoreString = "" + lastScore;
}
if (world.state == World.WORLD_STATE_NEXT_LEVEL) {
state = GAME_LEVEL_END;
}
if (world.state == World.WORLD_STATE_GAME_OVER) {
state = GAME_OVER;
if (lastScore >= Settings.highscores[4])
scoreString = "new highscore: " + lastScore;
else
scoreString = "score: " + lastScore;
Settings.addScore(lastScore);
Settings.save(game.getFileIO());
}
}
Little confused by what you are asking, but perhaps an else if?
if (event.type == TouchEvent.TOUCH_UP) {
/* do something for TOUCH_UP event */
} else if (event.type == TouchEvent.TOUCH_DOWN) {
/* do something for TOUCH_DOWN event */
} else {
/* do something else */
}
You can't stop a continue after you execute it.
Try adding break; where you want it to stop.

Categories

Resources