Regan Russell
10/26/2017, 2:56 AMdragas
10/26/2017, 8:01 AMhttps://i.imgur.com/27zZNih.png▾
langara
10/27/2017, 7:51 AMPaul Woitaschek
10/27/2017, 10:11 AMramonsgds
10/29/2017, 11:26 PMitsJoseph
10/30/2017, 8:40 AMdrulabs
10/30/2017, 8:47 AMitsJoseph
10/30/2017, 9:06 AMferoz_baig
10/30/2017, 1:10 PManderson.faro
10/30/2017, 7:17 PMramonsgds
10/31/2017, 12:47 AMapply plugin: 'kotlin-android-extensions'
on your build.gradle(Module:app)ramonsgds
10/31/2017, 12:49 AMfor person in list[position].persons
, is person
another variable created and thus passed by value or is it really list[position].person[some_index] behind the scenes?edwardwongtl
10/31/2017, 3:39 PM3
is being treated as Java primitive, while applying toInt()
forces the boxing to a Integer
The weird thing is that Kotlin should be able to do this automatically, maybe you can try to fire a bugrkeazor
11/02/2017, 1:21 AManstaendig
11/02/2017, 8:05 AMgildor
11/03/2017, 6:21 AModay
11/03/2017, 11:23 AMjw
11/04/2017, 4:38 PMsmilecs
11/05/2017, 10:34 AMuserData.token = response.body()?.token!!
preslav
11/06/2017, 9:26 AMGreg Stepniewski
11/06/2017, 9:32 AMbtn_list[i-1].isChecked = true/false
?Slackbot
11/06/2017, 10:39 PMagrosner
11/07/2017, 1:07 AMpreslav
11/07/2017, 9:45 AModay
11/07/2017, 10:32 AModay
11/07/2017, 2:41 PMPaul Woitaschek
11/07/2017, 9:43 PMphendrome
11/08/2017, 9:33 AMczuckie
11/08/2017, 10:39 AMMinty
11/08/2017, 11:26 AMMinty
11/08/2017, 11:26 AMczuckie
11/08/2017, 11:36 AM{
"questions": [
{
"q": "q1",
"a": [
"a1",
"a2",
"a3"
],
"ca": 1
},
{
"q": "q2",
"a": [
"a1",
"a2",
"a3"
],
"ca": 0
}
]
}
And get your system parsing that correctly, then work on selecting random questions from thatMinty
11/08/2017, 11:38 AM[["Q1.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Discussion Method can be used when: \n (A) The topic is very difficult\u00a0 (B) The topic is easy \n (C) The topic is difficult\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (D) All of the above \n ", "C"], ["Q2.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Which of the following is a teaching aid? \n (A) Working Model of Wind Mill\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (B) Tape Recorder \n (C) 16mm Film Projector\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (D) All the above \n ", "D"],
czuckie
11/08/2017, 11:39 AMMinty
11/08/2017, 11:40 AMczuckie
11/08/2017, 11:40 AMMinty
11/08/2017, 11:41 AMdata = []
for r in re.findall(r"Q\d+.*?(?=Q\d+)", soup.text, flags=re.S):
data_qa = []
rs = re.findall(r"Q\d+.*?(?=Answer.*?\:.*?[a-dA-D])", r.strip(), flags=re.S)
ra = re.findall(r"Answer.*?\:.*?[a-dA-D]", r.strip(), )
for rse in rs:
# print rse
data_qa.append(rse)
for rsa in ra:
if ra.index(rsa) == 0:
# print("The answer is "+ rsa.replace("Answer", "").replace(":", "").strip())
data_qa.append(rsa.replace("Answer", "").replace(":", "").strip())
# print "__________________________________________________________________"
data.append(data_qa)
for d in data:
if len(d)<2:
data.remove(d)
print d
jdump = json.dumps(data)
with file("qNa.json", "w+") as f:
f.write(jdump)
czuckie
11/08/2017, 11:42 AMdata class Question(val question:String, val answer:String)
Minty
11/08/2017, 11:43 AM[["Question1 and choices", "Answer"],["Q2","A"]
czuckie
11/08/2017, 11:43 AMMinty
11/08/2017, 11:44 AMdata class
outside oncreate
right? Can I do it in the main activity classs?czuckie
11/08/2017, 11:44 AMMinty
11/08/2017, 11:46 AMindex
in a list. How do I do that with a data class. I still don't understand the concept of data class. i guess I'll have to look it upczuckie
11/08/2017, 11:46 AMclass MainActivity : AppCompatActivity() {
data class Question(val question: String, val answer: String)
fun parseQuestions(rawQuestionJson: String): List<Question> {
TODO("Parse json")
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
parseQuestions("[[\"Question 1\",\"A\"],[\"Question 2\",\"B\"]]")
}
}
class Question(val question:String, val answer:String)
val q1 = Question("q1", "a")
val q2 = Question("q1", "a")
if (q1 == q2) {
println("They are equal")
}
Minty
11/08/2017, 11:49 AMczuckie
11/08/2017, 11:50 AMMinty
11/08/2017, 11:50 AMczuckie
11/08/2017, 11:51 AMMinty
11/08/2017, 11:51 AMczuckie
11/08/2017, 11:51 AMprivate fun parseQuestions(rawQuestionJson: String): List<Question> {
val result = mutableListOf<Question>()
val questionArray = JSONArray(rawQuestionJson)
for (i in 0..questionArray.length()) {
val question = questionArray.getJSONArray(i)
result += Question(question.getString(0), question.getString(1))
}
return result
}
Minty
11/08/2017, 11:54 AMczuckie
11/08/2017, 11:54 AMclass MainActivity : AppCompatActivity() {
data class Question(val question: String, val answer: String)
private fun parseQuestions(rawQuestionJson: String): List<Question> {
val result = mutableListOf<Question>()
val questionArray = JSONArray(rawQuestionJson)
for (i in 0..questionArray.length()) {
val question = questionArray.getJSONArray(i)
result += Question(question.getString(0), question.getString(1))
}
return result
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
var tenQuestions = parseQuestions("[[\"Question 1\",\"A\"],[\"Question 2\",\"B\"]]").shuffled().take(10)
TODO("Display ten questions")
}
}
org.json
which is shipped with androidvar tenQuestions = parseQuestions("[[\"Question 1\",\"A\"],[\"Question 2\",\"B\"]]").shuffled().take(10)
may look like black magic butvar tenQuestions = parseQuestions("...JSONHERE...")
.shuffled() // Randomises the order of list items
.take(10) // Take the first 10 items from the list
Minty
11/08/2017, 11:57 AMczuckie
11/08/2017, 11:58 AMMinty
11/08/2017, 12:00 PMczuckie
11/08/2017, 1:04 PM