"figuring out how to pass script between activities."
This commit is contained in:
parent
9b75e375e0
commit
eecf46161e
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@ -37,7 +37,7 @@
|
||||
<ConfirmationsSetting value="0" id="Add" />
|
||||
<ConfirmationsSetting value="0" id="Remove" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8 (1)" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
4
.idea/modules.xml
generated
4
.idea/modules.xml
generated
@ -2,7 +2,9 @@
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/MyApplication.iml" filepath="$PROJECT_DIR$/MyApplication.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/android.iml" filepath="$PROJECT_DIR$/android.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/android.iml" filepath="$PROJECT_DIR$/android.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
|
@ -9,6 +9,7 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
|
||||
<activity android:name=".ChoiceActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
@ -19,6 +19,7 @@ import java.util.List;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
public List<Hashtable<String, List>> script = new ArrayList<>();
|
||||
@ -30,13 +31,21 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
try {
|
||||
JSONArray test = new JSONArray(convertStreamToString(getResources().openRawResource(R.raw.script)));
|
||||
|
||||
readJson(test);
|
||||
} catch (JSONException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
//http://www.java2s.com/Code/Java/File-Input-Output/ConvertInputStreamtoString.htm
|
||||
|
||||
public static void readJson(JSONArray ScriptObject) throws JSONException {
|
||||
Integer length = ScriptObject.length();
|
||||
for (i = 0; i > length; i++) {
|
||||
JSONObject question = ScriptObject.getJSONObject(i);
|
||||
question
|
||||
}
|
||||
}
|
||||
|
||||
//http://www.java2s.com/Code/Java/File-Input-Output/ConvertInputStreamtoString.htm
|
||||
public static String convertStreamToString(InputStream is) throws IOException {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@ -60,10 +69,13 @@ public class MainActivity extends AppCompatActivity {
|
||||
public void Click(View v) {
|
||||
if (true) {
|
||||
Toast.makeText(this, " Please Make A Selection ", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
Intent intent = new Intent(this, ChoiceActivity.class);
|
||||
intent.putStringArrayListExtra("Text", (ArrayList<String>) script.get(1).get("Text"));
|
||||
intent.putIntegerArrayListExtra("Destination", (ArrayList<Integer>) script.get(1).get("Destination"));
|
||||
intent.putExtra("Question", (ArrayList<String>) script.get(1).get("Question"));
|
||||
intent.
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
[
|
||||
[
|
||||
{
|
||||
"question": "question 1:",
|
||||
"opts": [
|
||||
{
|
||||
"Text": "opt1",
|
||||
"DESTINATION": 1
|
||||
@ -8,8 +10,11 @@
|
||||
"Text": "opt2",
|
||||
"DESTINATION": 2
|
||||
}
|
||||
],
|
||||
[
|
||||
]
|
||||
},
|
||||
{
|
||||
"question": "question 2:",
|
||||
"opts": [
|
||||
{
|
||||
"Text": "opt1",
|
||||
"DESTINATION": 3
|
||||
@ -19,4 +24,5 @@
|
||||
"DESTINATION": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
@ -5,7 +5,7 @@ buildscript {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:2.3.0'
|
||||
classpath 'com.android.tools.build:gradle:2.2.3'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
|
Reference in New Issue
Block a user