これは私の最初のアクティビティです。
public class CheckAvailability extends Activity{
Button but1,but2;
EditText brName;
TextView txt1;
String text;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.availability);
brName =(EditText)findViewById(R.id.editText1);
but1 = (Button)findViewById(R.id.button5);
but2 = (Button)findViewById(R.id.button6);
txt1 = (TextView)findViewById(R.id.textView3);
but1.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
String result = null;
InputStream is = null;
StringBuilder sb=null;
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
//ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();
postParameters.add(new BasicNameValuePair("branchname", brName.getText().toString()));
//http post
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.0.2.2:8080/hello/AvailabilityResponse");
httppost.setEntity(new UrlEncodedFormEntity(postParameters));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
Log.e("log_tag", "Error in http connection"+e.toString());
}
//convert response to string
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
sb = new StringBuilder();
sb.append(reader.readLine() + "\n");
String line="0";
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
}catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}
Intent intent = new Intent(CheckAvailability.this , ListAtmActivity.class);
intent.putExtra("key", result);
startActivity(intent);}
});
このアクティビティから、その結果文字列を使用して 2 番目のアクティビティを呼び出しています。これは私の2番目の活動です。
public class ListAtmActivity extends Activity{
private static String url ="http://10.0.2.2:8080/hello/AvailabilityResponse";
private static final String TAG_ID = "id";
private static final String ATM_NO = "atmbrno";
private static final String ATM_PLACE = "atmbrname";
static InputStream is = null;
static String json = "";
static JSONArray jObj = null;
JSONArray contacts=null;
public class ListViewA extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_view2);
ListView lv= (ListView)findViewById(R.id.listview);
String[] from = new String[] {"col_1", "col_2"};
int[] to = new int[] { R.id.item2, R.id.item3};
String brName=getIntent().getExtras().getString("key");
List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
try {
contacts = new JSONArray(brName);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try{
for(int i = 0; i < contacts.length(); i++){
JSONObject json_data = contacts.getJSONObject(i);
System.out.print(contacts.length());
String atm_id = json_data.getString(ATM_NO);
String atm_name = json_data.getString(ATM_PLACE);
HashMap<String, String> map = new HashMap<String, String>();
map.put("col_1", atm_id);
map.put("col_2", atm_name);
fillMaps.add(map);
}
}
catch(JSONException e) {
e.printStackTrace();
}
SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.grid_item, from, to);
lv.setAdapter(adapter);
}
}}
しかし、インターフェイスに何も出力できません...空白の画面表示のみです。これの何が問題なのですか?