What I want to achieve is to use to spinners to select from town and then to town and then to retrieve the distance and time of travel that i have defined in my dist.js file. It works great when i use html in webview. but I don't want to use webview. Therefore how can i get the two spinners to calculate this?
Okay have tried but still nothing works. here is my code so far. Can you tell what i am doing wrong?
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
import org.json.JSONArray;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
public class MainActivity extends Activity{
Spinner s1;
Spinner s2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
s1 = (Spinner) findViewById(R.id.spinner1);
s2 = (Spinner) findViewById(R.id.spinner2);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.camp_sites, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s1.setAdapter(adapter);
InputStream is = context.getResources().openRawResource(R.raw.dist);
Writer writer = new StringWriter(is.available());
char[] buffer = new char[1024];
Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); {
try {
int n;
while ((n = reader.read(buffer)) != -1) {
writer.write(buffer, 0, n);
}
} finally {
reader.close();
}
String jsonString = writer.toString();
JSONArray json = new JSONArray(jsonString);}
}
public void onNothingSelected(AdapterView<?> parent) {
}
}
Thank you for helping me on this problem!!!