我想要实现的是使用微调器从城镇中选择,然后到城镇,然后检索我在 dist.js 文件中定义的旅行距离和时间。当我在 webview 中使用 html 时效果很好。但我不想使用 webview。因此,我怎样才能让两个微调器来计算呢?
好的,已经尝试过,但仍然没有任何效果。到目前为止,这是我的代码。你能告诉我我做错了什么吗?
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) {
}
}
谢谢你帮我解决这个问题!!!